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

feat: GCS provisioner using ADC or existing service account for access tokens #111

Merged

Conversation

man8pr
Copy link
Contributor

@man8pr man8pr commented Jan 22, 2024

What this PR changes/adds

IAM interface allows to use ADC or existing service account to generate access tokens, instead of creating and deleting new service accounts for this purpose.
GCS provisioner adapted to make use of the new functions provided by IAM.

Why it does that

The change avoids delays in the propagation of permissions to newly created service accounts.

Note

When using Application Default Credentials (i.e. when a service account is not specified), avoid user credentials and select the appropriate service account, http://cloud.google.com/docs/authentication/external/set-up-adc-on-cloud

Linked Issue(s)

Closes #110 #118

@man8pr man8pr added the feature_request New feature request, awaiting triage label Jan 22, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2024

Codecov Report

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

Comparison is base (b31f543) 63.52% compared to head (7a4f527) 60.06%.

Files Patch % Lines
...n/java/org/eclipse/edc/gcp/iam/IamServiceImpl.java 45.16% 13 Missing and 4 partials ⚠️
...a/org/eclipse/edc/gcp/common/GcpConfiguration.java 0.00% 3 Missing ⚠️
...connector/provision/gcp/GcsResourceDefinition.java 60.00% 2 Missing ⚠️
...connector/provision/gcp/GcsProvisionExtension.java 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
- Coverage   63.52%   60.06%   -3.46%     
==========================================
  Files          24       24              
  Lines         595      576      -19     
  Branches       30       30              
==========================================
- Hits          378      346      -32     
- Misses        205      217      +12     
- Partials       12       13       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@man8pr man8pr added the enhancement New feature or request label Jan 22, 2024
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

I think the scope of this PR is pretty vague, will we need both getServiceAccount and getOrCreateServiceAccount?
I agree with @paullatzelsperger that ApplicationDefaultCredentials scope is also misleading... you say that you introduced for testing reasons, but in fact it is part of the public API of the IamServiceImpl.

my suggestion would be to rephrase this PR as it is seen from the perspective of the caller (the provisioner, according to the description), that will help defining clearer interfaces and setting up the correct testing boundaries

@man8pr
Copy link
Contributor Author

man8pr commented Jan 23, 2024

I think the scope of this PR is pretty vague, will we need both getServiceAccount and getOrCreateServiceAccount? I agree with @paullatzelsperger that ApplicationDefaultCredentials scope is also misleading... you say that you introduced for testing reasons, but in fact it is part of the public API of the IamServiceImpl.

my suggestion would be to rephrase this PR as it is seen from the perspective of the caller (the provisioner, according to the description), that will help defining clearer interfaces and setting up the correct testing boundaries

Agreed and I will create an interface for ApplicationDefaultCredentials, and then an inner class for implementing it.
Regarding the scope, I am currently keeping both the getServiceAccount and getOrCreateServiceAccount, but plan to send another PR immediately after this one to remove the getOrCreateServiceAccount, because the provisioner will only use the former.

- IamServiceImpl.Builder now single-field
- Added AccessTokenProvider interface for adding app default credential provider and related test
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

as I said I see no end-to-end endeavor, is not clear who will use these new methods and how, they are dead code currently.

please start from the provisioner point of view, and, if that will become too broad to be coded in a single PR, please provide an explanation on how this will result at the end.

@man8pr
Copy link
Contributor Author

man8pr commented Jan 25, 2024

as I said I see no end-to-end endeavor, is not clear who will use these new methods and how, they are dead code currently.

please start from the provisioner point of view, and, if that will become too broad to be coded in a single PR, please provide an explanation on how this will result at the end.

SG I will update the PR and add the Provisioner perspective with an additional commit

GCS provisioner uses either application default credentials or existing service account to generate the access token for the sink
@man8pr man8pr changed the title feat: IAM service account impersonation and ADC access token feat: GCS provisioner using ADC or existing service account for access tokens Jan 25, 2024
@man8pr man8pr requested a review from ndr-brt January 25, 2024 16:13
- GCS provisioner finds service account name for access token from (first valid in sequence):
  - transfer request configuration
  - connector configuration from GcpConfiguration
  - application default credentials
- refactor serviceAccount to serviceAccountName for GcsResourceDefinition
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

just some nits, all good for the rest

@@ -89,28 +103,23 @@ public CompletableFuture<StatusResult<ProvisionResponse>> provision(
}
}

private String getServiceAccountName(GcsResourceDefinition resourceDefinition) {
if (resourceDefinition.getServiceAccountName() != null) {
// TODO verify service account name from resource definition before returning.
Copy link
Member

Choose a reason for hiding this comment

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

is this TODO supposed to be solved in this PR or is there an issue related to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This TODO requires more internal sync, there is currently no issue related but I would target this in another PR

GcpAccessToken token = null;

var serviceAccountName = getServiceAccountName(resourceDefinition);
if (serviceAccountName != null && !serviceAccountName.isEmpty()) {
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 serviceAccountName can never be null (please look at GcpConfiguration).

unrelated: I think that's not a good approach to use empty string as default value, it would be better to leave null for not-configured settings, so a simple not-null check will already permit to say if that configuration exists or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated GcpConfiguration, not returning null now

var uniqueServiceAccountDescription = generateUniqueServiceAccountDescription(processId, buckedName);
return iamService.getOrCreateServiceAccount(serviceAccountName, uniqueServiceAccountDescription);
}

@NotNull
private String sanitizeServiceAccountName(String processId) {
Copy link
Member

Choose a reason for hiding this comment

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

unused (same for other 2 methods in this class)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@man8pr man8pr requested a review from ndr-brt January 29, 2024 09:26
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

LGTM, please open an issue related to that TODO so it won't be forgotten

@ndr-brt ndr-brt merged commit f469278 into eclipse-edc:main Jan 29, 2024
14 checks passed
@man8pr man8pr deleted the feature/110_iam_existing_sa_adc_access_token branch March 8, 2024 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature_request New feature request, awaiting triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IAM add support for existing service account and ADC access token
4 participants