Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public class PolicyValidator implements IPolicyValidator {
* slash, in every environment.
* @param optOutUrl Core's opt-out URL. A given OPTOUT_BASE_URL override must equal it exactly, ignoring one
* trailing slash, in every environment.
* @param coreEnvironment Core's own environment. The declared environment check and the https requirement on
* optOutUrl apply only when this is {@link Environment#Production}; null (not configured)
* skips them.
* @param coreEnvironment Core's own environment. The declared environment check, the debug image rejection and
* the https requirement on optOutUrl apply only when this is {@link Environment#Production};
* null (not configured) skips them.
*/
public PolicyValidator(String attestationUrl, String optOutUrl, Environment coreEnvironment) {
if (coreEnvironment == Environment.Production && !isValidHttpsUrl(optOutUrl)) {
Expand Down Expand Up @@ -105,11 +105,14 @@ public String validate(TokenPayload payload) throws AttestationException {
return generateEnclaveId(isDebugMode, digest, env);
}

private static boolean checkConfidentialSpace(TokenPayload payload) throws AttestationException{
private boolean checkConfidentialSpace(TokenPayload payload) throws AttestationException{
if(!payload.isConfidentialSpaceSW()){
throw new AttestationClientException("Unexpected SW_NAME: " + payload.getSwName(), AttestationFailure.BAD_FORMAT);
}
var isDebugMode = payload.isDebugMode();
if(isDebugMode && this.coreEnvironment == Environment.Production){
throw new AttestationClientException("Confidential space debug image is not allowed in production. dbgstat: " + payload.getDbgStat(), AttestationFailure.BAD_FORMAT);
}
if(!isDebugMode && !payload.isStableVersion()){
throw new AttestationClientException("Confidential space image version is not stable.", AttestationFailure.BAD_FORMAT);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.uid2.shared.secure;

import com.uid2.shared.secure.gcpoidc.Environment;
import com.uid2.shared.secure.gcpoidc.IPolicyValidator;
import com.uid2.shared.secure.gcpoidc.ITokenSignatureValidator;
import com.uid2.shared.secure.gcpoidc.PolicyValidator;
Expand Down Expand Up @@ -194,6 +195,38 @@ public void testSignatureCheckFailed_EmptyAttestationDetails() throws Attestatio
attest(provider, ar -> assertTrue(ar.result().getAttestationDetails().isEmpty()));
}

@Test
public void testDebugModeRejectedInProdEvenWhenRegistered() throws AttestationException {
var debugPayload = TokenPayload.builder()
.gceZone("us-west1-b")
.dbgStat("enabled")
.swName("CONFIDENTIAL_SPACE")
.csSupportedAttributes(List.of("LATEST", "STABLE", "USABLE"))
.workloadImageDigest("sha256:b5a2c96250612366ea272ffac6d9744aaf4b45aacd96aa7cfcb931ee3b558259")
.restartPolicy("Never")
.envOverrides(Map.of(
PolicyValidator.ENV_ENVIRONMENT, "prod",
PolicyValidator.ENV_OPERATOR_API_KEY_SECRET_NAME, "projects/123/secrets/key/versions/1"
))
.build();
when(alwaysPassTokenValidator.validate(any())).thenReturn(debugPayload);
var debugEnclaveId = new PolicyValidator("https://core.example.com", "https://optout.example.com", null).validate(debugPayload);

var integProvider = new GcpOidcCoreAttestationService(alwaysPassTokenValidator,
List.of(new PolicyValidator("https://core.example.com", "https://optout.example.com", null)));
integProvider.registerEnclave(debugEnclaveId);
attest(integProvider, ar -> assertTrue(ar.result().isSuccess()));

var prodProvider = new GcpOidcCoreAttestationService(alwaysPassTokenValidator,
List.of(new PolicyValidator("https://core.example.com", "https://optout.example.com", Environment.Production)));
prodProvider.registerEnclave(debugEnclaveId);
attest(prodProvider, ar -> {
assertTrue(ar.succeeded());
assertFalse(ar.result().isSuccess());
assertEquals(AttestationFailure.BAD_FORMAT, ar.result().getFailure());
});
}

private static void attest(ICoreAttestationService provider, Handler<AsyncResult<AttestationResult>> handler) {
provider.attest(
ATTESTATION_REQUEST.getBytes(StandardCharsets.UTF_8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void verifyDifferentEnclaveId_DifferentImageDigest() throws AttestationEx

@Test
public void verifyDifferentEnclaveId_DebugMode() throws AttestationException {
var validator = new PolicyValidator(ATTESTATION_URL, OPT_OUT_URL, Environment.Production);
var validator = new PolicyValidator(ATTESTATION_URL, OPT_OUT_URL, Environment.Integration);
var payload1 = generateBasicPayload();
var enclaveId1 = validator.validate(payload1);

Expand Down