Skip to content
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

Fix cross-account deploys restricted by externalId #117

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

g-andrade
Copy link

@g-andrade g-andrade commented Oct 27, 2022

Issue

It's possible to restrict cross-account deploys to a specific externalId in IAM role policies.

Up until the present fix, however, such deploys with a custom externalId fail with HTTP 403 forbidden; removing the restriction from the IAM policy instantly allows for the deploy to happen.

My understanding of what's happening is:

  1. a new AWSCodeDeployPublisher instance receives the externalId through its constructor and saves it:
    public AWSCodeDeployPublisher(
    String s3bucket,
    String s3prefix,
    String applicationName,
    String deploymentGroupName,
    String deploymentConfig,
    String region,
    Boolean deploymentGroupAppspec,
    Boolean waitForCompletion,
    Long pollingTimeoutSec,
    Long pollingFreqSec,
    String credentials,
    String awsAccessKey,
    String awsSecretKey,
    String iamRoleArn,
    String externalId,
    String includes,
    String proxyHost,
    int proxyPort,
    String excludes,
    String subdirectory) {
    this.externalId = externalId;
  2. when using "iamRoleArn" as credentials, the instance will retrieve externalId from the descriptor:
    aws = AWSClients.fromIAMRole(
    this.region,
    this.iamRoleArn,
    this.getDescriptor().getExternalId(),
  3. but the descriptor instance initializes its own externalId randomly:
    public DescriptorImpl() {
    load();
    if (externalId == null) {
    setExternalId(UUID.randomUUID().toString());

Description of changes

Functional:

  • use AWSCodeDeployPublisher.externalId instead of the descriptor's

Tooling-related:

  • support building with recent versions of maven (HTTPS-less HTTP mirrors are now blocked)[*]
  • fix Javadoc generation in Java 17 (it broke the build)

[*] closes #107, #115 and #116

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

It's possible to restrict these in the cross-account IAM role policy[1].

Up until the present fix, however, the current implementation doesn't cover
that use case as expected:
* a new `AWSCodeDeployPublisher` instance receives the `externalId` through its
  constructor and saves it[2]
* when using `"iamRoleArn"` as credentials, the instance will retrieve
  `externalId` from the `descriptor`[3]
* but the descriptor instance initializes its own `externalId` randomly[4]

[1]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html
[2]: https://github.com/awslabs/aws-codedeploy-plugin/blob/40d7b24c95edef27f2879037ae1add30fc3f3831/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java#L108-L130
[3]: https://github.com/awslabs/aws-codedeploy-plugin/blob/40d7b24c95edef27f2879037ae1add30fc3f3831/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java#L204-L207
[4]: https://github.com/awslabs/aws-codedeploy-plugin/blob/40d7b24c95edef27f2879037ae1add30fc3f3831/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java#L460-L464
By Java 17 the `<tt>` HTML tag has been deprecated, presumably because
it switched to HTML5 (?).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant