-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow signers to specify allow list of oidc ids
- Also signer now throws KeylessSignerException Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
e174366
commit 929a0f6
Showing
7 changed files
with
178 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sigstore-java/src/main/java/dev/sigstore/KeylessSignerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2022 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.sigstore; | ||
|
||
public class KeylessSignerException extends Exception { | ||
public KeylessSignerException(String message) { | ||
super(message); | ||
} | ||
|
||
public KeylessSignerException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public KeylessSignerException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
sigstore-java/src/main/java/dev/sigstore/OidcIdentity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2023 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.sigstore; | ||
|
||
import dev.sigstore.oidc.client.OidcToken; | ||
import org.immutables.value.Value.Immutable; | ||
|
||
@Immutable | ||
public interface OidcIdentity { | ||
|
||
static OidcIdentity of(String identity, String issuer) { | ||
return ImmutableOidcIdentity.builder().identity(identity).issuer(issuer).build(); | ||
} | ||
|
||
static OidcIdentity from(OidcToken oidcToken) { | ||
return ImmutableOidcIdentity.builder() | ||
.identity(oidcToken.getSubjectAlternativeName()) | ||
.issuer(oidcToken.getIssuer()) | ||
.build(); | ||
} | ||
|
||
/** The user or machineId. */ | ||
String getIdentity(); | ||
|
||
/** The oidc issuing authority */ | ||
String getIssuer(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,36 @@ public void sign_production() throws Exception { | |
} | ||
} | ||
|
||
@Test | ||
@EnabledIfOidcExists(provider = OidcProviderType.GITHUB) | ||
// this test will only pass on the github.com/sigstore/sigstore-java repository | ||
public void sign_failGithubOidcCheck() throws Exception { | ||
var signer = | ||
KeylessSigner.builder() | ||
.sigstorePublicDefaults() | ||
.allowedOidcIdentities(List.of(OidcIdentity.of("[email protected]", "goose.com"))) | ||
.build(); | ||
var ex = | ||
Assertions.assertThrows(KeylessSignerException.class, () -> signer.sign(artifactDigests)); | ||
Assertions.assertEquals( | ||
"Obtained Oidc Token " | ||
+ OidcIdentity.of("github machine", "github.com") | ||
+ " does not match any identities in allow list", | ||
ex.getMessage()); | ||
} | ||
|
||
@Test | ||
@EnabledIfOidcExists(provider = OidcProviderType.GITHUB) | ||
// this test will only pass on the github.com/sigstore/sigstore-java repository | ||
public void sign_passGithubOidcCheck() throws Exception { | ||
var signer = | ||
KeylessSigner.builder() | ||
.sigstorePublicDefaults() | ||
.allowedOidcIdentities(List.of(OidcIdentity.of("[email protected]", "goog"))) | ||
.build(); | ||
signer.sign(artifactDigests); | ||
} | ||
|
||
@Test | ||
@EnabledIfOidcExists(provider = OidcProviderType.ANY) | ||
public void sign_staging() throws Exception { | ||
|