-
Couldn't load subscription status.
- Fork 27
Enable service account keys to be provided in base64 #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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this function able to figure out if the string that it's reading actually is encoded?
Uh oh!
There was an error while loading. Please reload this page.
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, the usual way to verify if a string is encoded in Go is to call
DecodeStringand check iferr == nil.Uh oh!
There was an error while loading. Please reload this page.
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.
hmm, I'm not sure if it is 100% reliable
Both of these print for me (no error) and the second one is not base64 encoded string.
The error is returned when there are spaces or other non alphanumerics in the string.
The second one (decoding of not-encoded string) is producing garbage string but it seems it is a "valid" string.
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 got your point, that makes sense. I believe your test has this behavior because "encodedserviceaccountkey" is a "valid" base64 encoded string in terms of structure.
The main point is when an actual service account key json is provided the
DecodeStringfunction will fail and an error is going to be returned.Another option (that I'd like to avoid if possible) would be to add a different field for the base64, like
GAE_CREDENTIALS_B64. I'd like to avoid this approach because it unnecessarily changes the plugin interface. But I'm not totally against it.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.
You're right that this should work in this type of field case.
I wonder if it would be helpful to indicate somehow to the users (log to the console) that decoding failed and it's going to be using the value as is. I'm thinking about cases where someone puts in invalid b64 string e.g. with extra whitespace at the end or similar (which was happening in the past).
The b64 values will come from an external source, not users in this use case, but who knows how people will use it in the future.
It may also be an overkill and what we have in the PR is good enough.
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.
That makes sense. I'll add the log output. It will definitely make it easier to debug when someone puts in an invalid base64 string.
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.
Just a thought: how about if you check the credential can be unmarshalled into it's JSON structure first? If it doesn't, then try decoding it and unmarshalling?
That way you are doing validation for both structure types.
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.
Hey @tonglil, I'm so sorry I haven't seen your comment before merging - just seeing it now. I think this is a good validation to have. In any case, the best validation is going to be provided by the gcloud command when it tries to activate the service account. I'm happy to add the JSON structure validation if that makes sense, tho.
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.
Nah you're right, let's let gcloud do the heavy lifting