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

Add support for Trusted Profile authentication #12

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

Conversation

Suruthi-G-K
Copy link
Member

@Suruthi-G-K Suruthi-G-K commented Mar 17, 2023

What this PR does / why we need it:
Added logic to support authentication using Trusted Profile. We are integrating COS as one of a storage provider in Loki. As part of this we are using ibm-cos-sdk-go package to communicate to COS. We want to authenticate to COS using Trusted Profile instead of Apikey so that we don't have to manage/rotate the Apikey.

Notes:
We created a new provider for trusted profile that is similar to the existing static provider by implementing provider interface

Suruthi-G-K and others added 3 commits March 17, 2023 19:05
Signed-off-by: Suruthi Ganesan Kalavathy <[email protected]>
Signed-off-by: Suruthi Ganesan Kalavathy <[email protected]>
Co-authored-by: shahulsonhal <[email protected]>
Signed-off-by: Suruthi Ganesan Kalavathy <[email protected]>
Signed-off-by: shahulsonhal <[email protected]>
- Update retrieve function to fetch token only if it is expired.
  Replaced `RequestToken` with `GetToken` function.
- Add test case for trusted profile retrieve function

Co-authored-by: Suruthi-G-K <[email protected]>
Signed-off-by: shahulsonhal <[email protected]>
// - Expires in (terms of seconds)
// - Expiration time
// Error object
//
Copy link
Member

Choose a reason for hiding this comment

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

can you avoid this change?

// Manadatory Refresh Timeout
// Timer
// Token Manager Client Do Operation
//
Copy link
Member

Choose a reason for hiding this comment

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

can you avoid also this change?


file, err := ioutil.TempFile(os.TempDir(), "crtoken")
require.NoError(t, err)
fmt.Println(file.Name())
Copy link
Member

@tareqmamari tareqmamari Mar 20, 2023

Choose a reason for hiding this comment

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

we don't need to print the file name.

Copy link
Member

Choose a reason for hiding this comment

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

Committed by mistake, removed.

@@ -281,7 +342,8 @@ func (tmm *tokenManagerMock2) Get() (*token.Token, error) {

// Mock Token Manager Two Constructor
// Returns:
// Mock Token Manager with IBM IAM Authentication Server Endpoint
//
// Mock Token Manager with IBM IAM Authentication Server Endpoint
Copy link
Member

Choose a reason for hiding this comment

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

could you also avoid this change?

// Trusted Profile Name
// Compute Resource Token File Path
// IBM IAM Authentication Server Endpoint
// Service Instance ID
Copy link
Member

Choose a reason for hiding this comment

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

wondering why we need service instance id here?

return provider
}

if trustedProfileName == "" && trustedProfileID == "" {
Copy link
Member

@tareqmamari tareqmamari Mar 20, 2023

Choose a reason for hiding this comment

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

we can use the TP name, ID. Something we need to be clear of in the docs/comments.

Copy link
Member

Choose a reason for hiding this comment

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

True. As far as I understood, the go-sdk-core does not have an implementation to support the profile_crn.

//
// TrustedProfileProvider expired or not - boolean
func (p *TrustedProfileProvider) IsExpired() bool {
return true
Copy link
Member

Choose a reason for hiding this comment

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

why it is always true but not false?

Copy link
Member

Choose a reason for hiding this comment

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

The GetToken function is actually checking the expiration before it's trying to get the token from server. Also the token in authenticator is not accessible in IsExpired function since it is not an exported variable and we won't be able to check the expiration from our side. I think it should be okay to return true since that logic is handled inside the GetToken function. Also updated the doc comment.

@shahulsonhal shahulsonhal force-pushed the trusted-profile branch 2 times, most recently from bbba477 to 1adc469 Compare March 20, 2023 15:51
// Provider Name
// AWS Config
// Trusted Profile Name
// Service Profile ID
Copy link
Member

Choose a reason for hiding this comment

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

I think you mean Trusted Profile ID.

Signed-off-by: shahulsonhal <[email protected]>

authenticator, err := core.NewContainerAuthenticatorBuilder().
SetIAMProfileName(trustedProfileName).
SetIAMProfileID(trustedProfileID).
Copy link
Member

Choose a reason for hiding this comment

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

What happens if you only set the name, but not the id, as far as I know, it is sufficient to either use the name or ID.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it is sufficient to set either ID/TP name. We tested this logic using Unit test case and we were able to authenticate using either one of them

Copy link
Member

@shahulsonhal shahulsonhal Mar 20, 2023

Choose a reason for hiding this comment

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

You are correct. We added profile id to just give user a choice over name or id. It will work:

  • if we set the profile name only
  • if we set the profile id only
  • if we set both it should be of the same trusted profile, otherwise authentication will fail.

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.

3 participants