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

Replumb AssumeRole (AWS) #2306

Conversation

2uasimojo
Copy link
Member

@2uasimojo 2uasimojo commented Jun 12, 2024

Simplify the AssumeRole flow: Rather than doing it via credential_process as a callback from within the creds file used by the provision pod, flatten this out so the AssumeRole is done implicitly by the AWS SDK.

This flow remains unchanged:

The clusterdeployment controller:

  • Copies the service provider secret into the CD namespace
  • Creates an AWS credentials secret
  • Creates the provision pod

The provision pod:

  • Loads the credentials secret
  • Projects the AWS config therein onto the file system
  • Invokes the installer

The installer:

  • Creates an AWS client using that config file
  • Proceeds with installation

Before this commit:
The AWS config contained a credential_process which invoked hiveutil install-manager aws-credentials which...

  • Loaded the service provider secret
  • Created an AWS client
  • Used the client to AssumeRole and generate credentials with a 15m expiration
  • Printed the credentials to stdout in the format expected by AWS.

Per AWS docs[1], the SDK will automatically rerun the credential_process before the expiration time to refresh the creds.

With this commit:
The clusterdeployment controller loads the service provider secret and folds it into the AWS config as a separate profile, referenced from the default via source_profile:

[default]
source_profile = source
role_arn = arn:aws:iam::123456789012:role/assume-role-customer

[profile source]
aws_access_key_id: ABCDEFGHIJKLMNOPQRST
aws_secret_access_key: 1234567890abcdefghijklmnopqrstuvwxyz0123
role_arn = arn:aws:iam::210987654321:role/assume-role-provider

Per AWS docs[2], the SDK will use the source creds to AssumeRole to generate temporary creds, which it will automatically refresh as they expire -- i.e. natively performing the same function as hiveutil install-manager aws-credentials.

As a security measure, we will now check AWS config/credential files for credential_process, and explode if found. However, since existing clusters in the field may still be configured with the old mechanism in the relevant Secrets, we will convert such Secrets to use the new mechanism.

[1] https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-sourcing-external.html
[2] https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html

HIVE-2485
HIVE-2529

@openshift-ci openshift-ci bot requested review from dlom and suhanime June 12, 2024 20:31
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 12, 2024
@cebarks
Copy link

cebarks commented Jun 12, 2024

This issue has been assigned CVE-2024-25133 by Red Hat Product Security.

@2uasimojo
Copy link
Member Author

/cc @abutcher @jharrington22
/assign @suhanime

@2uasimojo
Copy link
Member Author

/retest

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 6.50407% with 115 lines in your changes missing coverage. Please review.

Project coverage is 58.54%. Comparing base (1fce770) to head (13ea4f4).
Report is 6 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2306      +/-   ##
==========================================
+ Coverage   58.51%   58.54%   +0.02%     
==========================================
  Files         182      181       -1     
  Lines       25884    25863      -21     
==========================================
- Hits        15147    15141       -6     
+ Misses       9460     9447      -13     
+ Partials     1277     1275       -2     
Files Coverage Δ
...roller/awsprivatelink/awsprivatelink_controller.go 67.81% <100.00%> (ø)
contrib/pkg/utils/azure/azure.go 0.00% <0.00%> (ø)
contrib/pkg/utils/gcp/gcp.go 0.00% <0.00%> (ø)
pkg/controller/clusterdeprovision/awsactuator.go 34.48% <0.00%> (ø)
pkg/controller/dnszone/dnszone_controller.go 28.79% <0.00%> (ø)
pkg/controller/hibernation/aws_actuator.go 64.36% <0.00%> (ø)
...g/controller/machinepool/machinepool_controller.go 53.48% <0.00%> (ø)
contrib/pkg/utils/openstack/openstack.go 0.00% <0.00%> (ø)
contrib/pkg/utils/ovirt/ovirt.go 0.00% <0.00%> (ø)
contrib/pkg/utils/vsphere/vsphere.go 0.00% <0.00%> (ø)
... and 8 more

@2uasimojo
Copy link
Member Author

/override ci/prow/security

Addressed via #2308

Copy link
Contributor

openshift-ci bot commented Jun 12, 2024

@2uasimojo: Overrode contexts on behalf of 2uasimojo: ci/prow/security

In response to this:

/override ci/prow/security

Addressed via #2308

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@2uasimojo
Copy link
Member Author

/hold for testing

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2024
@@ -774,7 +774,7 @@ func (r *ReconcileClusterDeployment) setupAWSCredentialForAssumeRole(cd *hivev1.
return nil
}

return install.AWSAssumeRoleCLIConfig(r.Client, cd.Spec.Platform.AWS.CredentialsAssumeRole, install.AWSAssumeRoleSecretName(cd.Name), cd.Namespace, cd, r.scheme)
return install.AWSAssumeRoleConfig(r.Client, cd.Spec.Platform.AWS.CredentialsAssumeRole, install.AWSAssumeRoleSecretName(cd.Name), cd.Namespace, cd, r.scheme)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same path for deporovisions or do we need to generate credentials there too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprovision path is below...

@@ -478,6 +478,6 @@ func (r *ReconcileClusterDeprovision) setupAWSCredentialForAssumeRole(cd *hivev1
return nil
}

return install.AWSAssumeRoleCLIConfig(r.Client, cd.Spec.Platform.AWS.CredentialsAssumeRole, install.AWSAssumeRoleSecretName(cd.Name), cd.Namespace, cd, r.scheme)
return install.AWSAssumeRoleConfig(r.Client, cd.Spec.Platform.AWS.CredentialsAssumeRole, install.AWSAssumeRoleSecretName(cd.Name), cd.Namespace, cd, r.scheme)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...here

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2024
@jharrington22
Copy link
Contributor

jharrington22 commented Jun 24, 2024

Overall LGTM @2uasimojo

@2uasimojo 2uasimojo force-pushed the HIVE-2485-2529/nix-credential_process branch from ffeac4a to 4d93e26 Compare July 12, 2024 15:31
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2024
Simplify the AssumeRole flow: Rather than doing it via
`credential_process` as a callback from within the creds file used by
the provision pod, flatten this out so the AssumeRole is done implicitly
by the AWS SDK.

This flow remains unchanged:

The clusterdeployment controller:
- Copies the service provider secret into the CD namespace
- Creates an AWS credentials secret
- Creates the provision pod

The provision pod:
- Loads the credentials secret
- Projects the AWS config therein onto the file system
- Invokes the installer

The installer:
- Creates an AWS client using that config file
- Proceeds with installation

Before this commit:
The AWS config contained a `credential_process` which invoked
`hiveutil install-manager aws-credentials` which...
- Loaded the service provider secret
- Created an AWS client
- Used the client to AssumeRole and generate credentials with a 15m
expiration
- Printed the credentials to stdout in the format expected by AWS.

Per AWS docs[1], the SDK will automatically rerun the
`credential_process` before the expiration time to refresh the creds.

With this commit:
The clusterdeployment controller loads the service provider secret and
folds it into the AWS config as a separate profile, referenced from the
default via `source_profile`:

```
[default]
source_profile = source
role_arn = arn:aws:iam::123456789012:role/assume-role-customer

[profile source]
aws_access_key_id: ABCDEFGHIJKLMNOPQRST
aws_secret_access_key: 1234567890abcdefghijklmnopqrstuvwxyz0123
role_arn = arn:aws:iam::210987654321:role/assume-role-provider
```

Per AWS docs[2], the SDK will use the source creds to AssumeRole to
generate temporary creds, which it will automatically refresh as they
expire -- i.e. natively performing the same function as `hiveutil
install-manager aws-credentials`.

[1] https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-sourcing-external.html
[2] https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html

HIVE-2485
HIVE-2529
@2uasimojo 2uasimojo force-pushed the HIVE-2485-2529/nix-credential_process branch from 7a260f9 to 9eeeb60 Compare July 15, 2024 20:21
As a security measure, check AWS config/credential files for
`credential_process`, and explode if found.

We used to use `credential_process` deliberately to AssumeRole for STS
clusters. A prior commit switched this over to use a different
mechanism, but existing clusters in the field may still be configured
with the old mechanism in the relevant Secrets. Convert such Secrets to
use the new mechanism.

HIVE-2485
@2uasimojo 2uasimojo force-pushed the HIVE-2485-2529/nix-credential_process branch from 9eeeb60 to 13ea4f4 Compare July 15, 2024 20:26
@jstuever
Copy link
Contributor

/cc

@openshift-ci openshift-ci bot requested a review from jstuever July 15, 2024 20:58
@2uasimojo
Copy link
Member Author

/assign @jstuever

@jstuever
Copy link
Contributor

/assign

@jstuever
Copy link
Contributor

/hold for pre-merge testing

Copy link
Contributor

@jstuever jstuever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2024
Copy link
Contributor

openshift-ci bot commented Jul 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 2uasimojo, jstuever

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@2uasimojo
Copy link
Member Author

MachinePool scaling, hopefully a flake

/test e2e-gcp

@2uasimojo
Copy link
Member Author

@jharrington22 agrees to merge.

/override "Red Hat Konflux / hive-on-pull-request"

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 17, 2024
Copy link
Contributor

openshift-ci bot commented Jul 17, 2024

@2uasimojo: Overrode contexts on behalf of 2uasimojo: Red Hat Konflux / hive-on-pull-request

In response to this:

@jharrington22 agrees to merge.

/override "Red Hat Konflux / hive-on-pull-request"

/hold cancel

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD c5571a9 and 2 for PR HEAD 13ea4f4 in total

Copy link
Contributor

openshift-ci bot commented Jul 17, 2024

@2uasimojo: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 5ba8466 into openshift:master Jul 17, 2024
12 of 13 checks passed
@2uasimojo 2uasimojo deleted the HIVE-2485-2529/nix-credential_process branch July 18, 2024 16:48
2uasimojo added a commit to 2uasimojo/hive that referenced this pull request Jul 19, 2024
A previous commit (openshift#2306 / 13ea4f4) put in checks to forbid the use of
`credential_process` in AWS config/credentials files. It turns out that
AWS accepts this key case-insensitively, so this commit updates our
checks accordingly.

HIVE-2485
2uasimojo added a commit to 2uasimojo/hive that referenced this pull request Jul 31, 2024
A previous commit (openshift#2306 / 13ea4f4) put in checks to forbid the use of
`credential_process` in AWS config/credentials files. It turns out that
AWS accepts this key case-insensitively, so this commit updates our
checks accordingly.

HIVE-2485

(cherry picked from commit 229f705)
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/hive that referenced this pull request Aug 1, 2024
A previous commit (openshift#2306 / 13ea4f4) put in checks to forbid the use of
`credential_process` in AWS config/credentials files. It turns out that
AWS accepts this key case-insensitively, so this commit updates our
checks accordingly.

HIVE-2485

(cherry picked from commit 229f705)
2uasimojo added a commit to 2uasimojo/hive that referenced this pull request Aug 2, 2024
A previous commit (openshift#2306 / 13ea4f4) put in checks to forbid the use of
`credential_process` in AWS config/credentials files. It turns out that
AWS accepts this key case-insensitively, so this commit updates our
checks accordingly.

HIVE-2485

(cherry picked from commit 229f705)
(cherry picked from commit 3fc318b)
2uasimojo added a commit to 2uasimojo/hive that referenced this pull request Aug 27, 2024
A previous commit (openshift#2306 / 13ea4f4) put in checks to forbid the use of
`credential_process` in AWS config/credentials files. It turns out that
AWS accepts this key case-insensitively, so this commit updates our
checks accordingly.

HIVE-2485

(cherry picked from commit 229f705)
(cherry picked from commit 3fc318b)
(cherry picked from commit 26ef2e3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants