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

Use md5 hash as role session name when assuming into customer's support role #283

Conversation

AlexVulaj
Copy link
Contributor

What type of PR is this?

feature

What this PR does / Why we need it?

backplane-cli passes the SRE's email address as a role session name when assuming a customer's support role. We should not pass any SRE usernames to a customer when assuming into their account.

Which Jira/Github issue(s) does this PR fix?

https://issues.redhat.com/browse/OSD-19901

Special notes for your reviewer

Pre-checks (if applicable)

  • Ran unit tests locally
  • Validated the changes in a cluster
  • Included documentation changes with PR

@codecov-commenter
Copy link

codecov-commenter commented Dec 8, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (52a842d) 46.83% compared to head (5d3d480) 45.87%.
Report is 32 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #283      +/-   ##
==========================================
- Coverage   46.83%   45.87%   -0.97%     
==========================================
  Files          53       53              
  Lines        3540     3758     +218     
==========================================
+ Hits         1658     1724      +66     
- Misses       1621     1759     +138     
- Partials      261      275      +14     
Files Coverage Δ
pkg/awsutil/sts.go 53.38% <50.00%> (ø)
cmd/ocm-backplane/cloud/common.go 16.35% <0.00%> (-0.54%) ⬇️

... and 5 files with indirect coverage changes

assumeRoleRetryBackoff = 5 * time.Second
assumeRoleMaxRetries = 3
assumeRoleRetryBackoff = 5 * time.Second
assumeCustomerRoleSessionName = "RH-SRE"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, I feel that bp-cli may use ISV's for connecting to the cluster in the near future. In that case, this logic may not be accurate.
Ideally, we should move some of the assumed role logic to bp-api endpoint where API decide how to determine the session-name based on some other factors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've updated the API to determine the role session name that should be used, but the actual AssumeRole logic needs to be done client side since we use individual SRE credentials for the isolated backplane flow.

https://gitlab.cee.redhat.com/service/backplane-api/-/merge_requests/329

cmd/ocm-backplane/cloud/common.go Outdated Show resolved Hide resolved
@AlexVulaj AlexVulaj force-pushed the generic-role-session-name-assume-customer-role branch from 3bd1b49 to 657f5b3 Compare December 11, 2023 19:59
@AlexVulaj AlexVulaj changed the title Use 'RH-SRE' as role session name when assuming into customer's support role Use md5 hash as role session name when assuming into customer's support role Dec 11, 2023
@AlexVulaj AlexVulaj force-pushed the generic-role-session-name-assume-customer-role branch 5 times, most recently from 337f8bb to cd24a6d Compare December 11, 2023 20:26
roleArnSession := awsutil.RoleArnSession{RoleArn: namedRoleArnEntry.Arn}
if namedRoleArnEntry.Name == CustomerRoleArnName {
data := []byte(email)
roleArnSession.RoleSessionName = fmt.Sprintf("%x", md5.Sum(data)) //nolint:gosec

Choose a reason for hiding this comment

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

Is it possible to get this from the backplane API? My concern is that an update to this in the CLI or API may mean they diverge in the future, it would be good to keep this consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's definitely possible - it comes down to how quickly we want this out the door.

To go this route, we would add a new API endpoint that takes a string and returns an md5 hash, using the same existing functions that are used in the API today for performing that conversion. Then the bp cli would call that endpoint instead.

I'm happy to go that route, and then we can keep this PR in a "hold" until that API change gets released. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually another thought - since this is only for the new flow, we could update the response object of the existing API call to include a new property for the role session name to be used for the customer's support role. That would be substantially less overhead and allow us quicker turnover.

@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 Dec 12, 2023
@AlexVulaj AlexVulaj force-pushed the generic-role-session-name-assume-customer-role branch from cd24a6d to 5d3d480 Compare January 2, 2024 17:04
@AlexVulaj
Copy link
Contributor Author

/unhold

API changes have been promoted to production https://gitlab.cee.redhat.com/service/app-interface/-/merge_requests/92517

@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 Jan 3, 2024
@bmeng
Copy link
Contributor

bmeng commented Jan 4, 2024

    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "xxxxxx:RH-SRE-bmeng_sre.openshift",
        "arn": "arn:aws:sts::xxxxx:assumed-role/ManagedOpenShift-Support-98sn7d/RH-SRE-bmeng_sre.openshift",
        "accountId": "xxxxx",
        "accessKeyId": "xxxxx",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "xxxxxx",
                "arn": "arn:aws:iam::xxxxx:role/ManagedOpenShift-Support-98sn7d",
                "accountId": "xxxxx",
                "userName": "ManagedOpenShift-Support-98sn7d"
            },

I still can see my user name in the cloudtrail, but it is not in the session part. I assume it is expected for now?

@AlexVulaj
Copy link
Contributor Author

@bmeng since the ticket specifically calls out the session name, I think we can go forward from here. I've started a thread here for further guidance on the principal being visible in cloudtrail:
https://redhat-internal.slack.com/archives/C058T1YEDPV/p1704395248986019

@bmeng
Copy link
Contributor

bmeng commented Jan 9, 2024

As discussed in slack, the scope for this pr should be limit the info from the session, for the rest parts we can cover them separately.
/lgtm

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

openshift-ci bot commented Jan 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlexVulaj, bmeng

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 9, 2024
Copy link
Contributor

openshift-ci bot commented Jan 9, 2024

@AlexVulaj: 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/test-infra repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 4321f0b into openshift:main Jan 9, 2024
7 checks passed
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.

5 participants