Google authentication overhaul#3448
Conversation
| } | ||
| } | ||
|
|
||
| def loadFromJson(json: String, scopes: Seq[String])(implicit system: ClassicActorSystemProvider): Credentials = { |
There was a problem hiding this comment.
This is intentionally public, to allow for programmatic instantiation of credentials from a loaded JSON file, something we use in Akka platform.
0ed45d5 to
a658924
Compare
|
This is failing because mima does not like the fact that |
a658924 to
0b8e043
Compare
johanandren
left a comment
There was a problem hiding this comment.
Changes looks good so far.
Needs Java APIs for the public parts.
Mima filters would go in a text file google-common/src/main/mima-filters/10.0.1.backwards.excludes/goggle-auth-overhaul.excludes, you can copy the suggested ProblemFilters.exclude entries from the mima output as individual lines into that file.
| * This class is intended for users to implement themselves to provide a custom means of loading Google OAuth2 | ||
| * credentials. | ||
| */ | ||
| trait CustomOAuth2Credentials { |
There was a problem hiding this comment.
We'll also need a Java version of this with CompletionStage and Pair rather than Scala types, not sure if the best thing there would be some clever naming or introduce scaladsl and javadsl packages like generally do.
There was a problem hiding this comment.
I've done this by using the existing Google scaladsl and javadsl packages.
| import scala.io.Source | ||
|
|
||
| object ApplicationDefaultCredentials { | ||
| def apply(c: Config, scopes: Seq[String])(implicit system: ClassicActorSystemProvider): Credentials = { |
There was a problem hiding this comment.
Add Java create methods parallel with apply, and loadFromJson that accept Java collections etc. as parameters and doesn't use implicit.
Scaladoc on the methods with /** Java API */ or /** Scala API */ to make the distinction extra clear for users, so add that.
0b8e043 to
d284869
Compare
|
I've made the following changes:
|
d284869 to
b6dffd4
Compare
Fixes akka#3447 and akka#3446. This adds a number of features and improves Google authentication. * Project ID is no longer always provided by the credentials provider. It's now an Option, which means credentials provider that are not able to provide a project ID can be implemented. * A new project-id parameter has been introduced at the top level of the Alpakka Google configuration. This takes precedence, then the optional project id provided by the credential provider, and then the default project id is used, which is read from the GCP_PROJECT or GOOGLE_CLOUD_PROJECT environment variables. * application-default has been reworked, and is now more robust. Instead of each provider being responsible for loading the file itself, and this selecting one based on which one didn't fail to load, the type field of the application JSON file is read, to decide what type of credentials to read. Failure then results in attempting to load GCE credentials. * A new credentials provider has been added, external account. This allows workload identity to work, for example, in GitHub actions. * Credentials can now be closed. This means that when dynamically loading credentials, resources, such as the actors running the caching stream for OAuth2 credentials, can be cleaned up when the credentials are no longer needed. * A new custom OAuth2 credentials class has been created, allowing custom access token loading strategies, which is useful on platforms where an access token is provided in an environment variable via workload identity. I've been careful to ensure that this is backwards compatible, but the following scenarios may break: * If someone is relying on the application-default provider, but they have placed configuration in one of the other providers, the old application-default provider would read that config. Now it doesn't. The solution is to be specific about which provider you want to use. * If someone has generated their own application json file without the type parameter, this will break the application-default provider. This parameter is considered compulsory by the Google SDK.
b6dffd4 to
9f05ff3
Compare
Fixes #3447 and #3446.
This adds a number of features and improves Google authentication.
project-idparameter has been introduced at the top level of the Alpakka Google configuration. Rather than just loading the project id from the credentials, this is now read first, and takes precedence. If not provided, then we use the optional project id from the credentials provider, and if that's not provided, we then use another new configuration parameter calleddefault-project-id, which is configured to read the project id from environment variables, egGCP_PROJECTorGOOGLE_CLOUD_PROJECT. In many environments, eg when workload identity is being used, these environment variables may be automatically set. This is actually an important feature, because the project id from the credentials provider is tied to which project your principal is in, but there's no reason why that project must be the same project that you want to access. Google principals are global, you can grant a service account in one project access to GCP in another, for example.application-defaultcredentials provider has been reworked, and is now more robust. Instead of each provider being responsible for loading the file itself, and this selecting one based on which one didn't fail to load, the type field of the application JSON file is read, to decide what type of credentials to read. So, a newpathparameter has been added for what to use whenapplication-defaultis configured. Failure to configure from the JSON file results in attempting to load GCE credentials.close()public API method being added. This means that when dynamically loading credentials, resources, such as the actors running the caching stream for OAuth2 credentials, can be cleaned up when the credentials are no longer needed.I've been careful to ensure that this is backwards compatible, there's no binary breakages, but the following scenarios may break:
provider = service-account, that used to work, but it doesn't now. The solution is to be specific about which provider you want to use.