-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add External ID parameter to AWS converter #57
base: master
Are you sure you want to change the base?
Changes from all commits
6422d1d
fc53422
a007e07
0c6890e
9abbf7d
1d3ba2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
# this is the jenkins id. | ||
name: "test-aws-credentials" | ||
labels: | ||
# so we know what type it is. | ||
"jenkins.io/credentials-type": "aws" | ||
annotations: | ||
# description - can not be a label as spaces are not allowed | ||
"jenkins.io/credentials-description" : "credentials from Kubernetes" | ||
type: Opaque | ||
stringData: | ||
accessKey: "" | ||
secretKey: "" | ||
iamRoleArn: IamRoleArn | ||
iamExternalId: IamExternalID |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public class AWSCredentialsConvertorTest { | |
String secretKey= "Pa$$word"; | ||
String iamRoleArn = "ecr:eu-west-1:86c8f5ec-1ce1-4e94-80c2-18e23bbd724a"; | ||
String iamMfaSerialNumber = "GAHT12345678"; | ||
String iamExternalId = "ext-id"; | ||
|
||
@Test | ||
public void canConvert() throws Exception { | ||
|
@@ -71,6 +72,7 @@ public void canConvertAValidSecret() throws Exception { | |
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamRoleArn is mapped correctly", credential.getIamRoleArn(), is(iamRoleArn)); | ||
assertThat("credential iamMfaSerialNumber is mapped correctly", credential.getIamMfaSerialNumber(), is(iamMfaSerialNumber)); | ||
assertThat("credential iamExternalId is mapped correctly", credential.getIamExternalId(), is(iamExternalId)); | ||
} | ||
} | ||
|
||
|
@@ -107,6 +109,7 @@ public void canConvertAValidMappedSecret() throws Exception { | |
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamRoleArn is mapped correctly", credential.getIamRoleArn(), is(iamRoleArn)); | ||
assertThat("credential iamMfaSerialNumber is mapped correctly", credential.getIamMfaSerialNumber(), is(iamMfaSerialNumber)); | ||
assertThat("credential iamExternalId is mapped correctly", credential.getIamExternalId(), is(iamExternalId)); | ||
} | ||
} | ||
|
||
|
@@ -126,6 +129,7 @@ public void canConvertAValidSecretWithNoDescription() throws Exception { | |
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamRoleArn is mapped correctly", credential.getIamRoleArn(), is(iamRoleArn)); | ||
assertThat("credential iamMfaSerialNumber is mapped correctly", credential.getIamMfaSerialNumber(), is(iamMfaSerialNumber)); | ||
assertThat("credential iamExternalId is mapped correctly", credential.getIamExternalId(), is(iamExternalId)); | ||
} | ||
} | ||
|
||
|
@@ -144,6 +148,7 @@ public void canConvertAValidSecretWithNoIamRole() throws Exception { | |
assertThat("credential accessKey is mapped correctly", credential.getAccessKey(), is(accessKey)); | ||
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamMfaSerialNumber is mapped correctly", credential.getIamMfaSerialNumber(), is(iamMfaSerialNumber)); | ||
assertThat("credential iamExternalId is mapped correctly", credential.getIamExternalId(), is(iamExternalId)); | ||
} | ||
} | ||
|
||
|
@@ -162,6 +167,25 @@ public void canConvertAValidSecretWithNoIamMfa() throws Exception { | |
assertThat("credential accessKey is mapped correctly", credential.getAccessKey(), is(accessKey)); | ||
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamRoleArn is mapped correctly", credential.getIamRoleArn(), is(iamRoleArn)); | ||
assertThat("credential iamExternalId is mapped correctly", credential.getIamExternalId(), is(iamExternalId)); | ||
} | ||
} | ||
|
||
@Test | ||
public void canConvertAValidSecretWithNoIamExternalId() throws Exception { | ||
AWSCredentialsConvertor convertor = new AWSCredentialsConvertor(); | ||
|
||
try (InputStream is = get("validMissingIamExternalId.yaml")) { | ||
Secret secret = Serialization.unmarshal(is, Secret.class); | ||
assertThat("The Secret was loaded correctly from disk", notNullValue()); | ||
AWSCredentialsImpl credential = convertor.convert(secret); | ||
assertThat(credential, notNullValue()); | ||
assertThat("credential id is mapped correctly", credential.getId(), is("a-test-aws")); | ||
assertThat("credential description is mapped correctly", credential.getDescription(), is(emptyString())); | ||
assertThat("credential scope is mapped correctly", credential.getScope(), is(CredentialsScope.GLOBAL)); | ||
assertThat("credential accessKey is mapped correctly", credential.getAccessKey(), is(accessKey)); | ||
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamRoleArn is mapped correctly", credential.getIamRoleArn(), is(iamRoleArn)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you add a check that the external id check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jtnord can you elaborate or add an example? None of the other missing item validations are explicitely checking if that value is null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
|
@@ -182,6 +206,7 @@ public void canConvertAValidScopedSecret() throws Exception { | |
assertThat("credential secretKey is mapped correctly", credential.getSecretKey().getPlainText(), is(secretKey)); | ||
assertThat("credential iamRoleArn is mapped correctly", credential.getIamRoleArn(), is(iamRoleArn)); | ||
assertThat("credential iamMfaSerialNumber is mapped correctly", credential.getIamMfaSerialNumber(), is(iamMfaSerialNumber)); | ||
assertThat("credential iamExternalId is mapped correctly", credential.getIamExternalId(), is(iamExternalId)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
# this is the jenkins id. | ||
name: "a-test-aws" | ||
labels: | ||
# so we know what type it is. | ||
"jenkins.io/credentials-type": "aws" | ||
annotations: | ||
# description - can not be a label as spaces are not allowed | ||
"jenkins.io/credentials-description" : "credentials from Kubernetes" | ||
# map the accessKey field to a | ||
"jenkins.io/credentials-keybinding-accessKey" : "a" | ||
# map the secretKey field to s | ||
"jenkins.io/credentials-keybinding-secretKey" : "s" | ||
# map the iamRoleArn field to r | ||
"jenkins.io/credentials-keybinding-iamRoleArn" : "r" | ||
# map the iamMfaSerialNumber field to m | ||
"jenkins.io/credentials-keybinding-iamMfaSerialNumber" : "m" | ||
type: Opaque | ||
data: | ||
# UTF-8 base64 encoded | ||
a: QUJDMTIzNDU2 #ABC123456 | ||
s: UGEkJHdvcmQ= #Pa$$word | ||
r: ZWNyOmV1LXdlc3QtMTo4NmM4ZjVlYy0xY2UxLTRlOTQtODBjMi0xOGUyM2JiZDcyNGE= #ecr:eu-west-1:86c8f5ec-1ce1-4e94-80c2-18e23bbd724a | ||
m: R0FIVDEyMzQ1Njc4 #GAHT12345678 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't referenced from the examples page (or elsewhere?
Could you update the existing Aws example with some sommebts for optionality of the fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. Do you mean that I should add a reference within the examples README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes these docs/ will not be visible I documentation unless you reference them somewhere.
https://github.com/jenkinsci/kubernetes-credentials-provider-plugin/blob/master/docs/examples/README.md#aws-credentials