-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: Migrate auth commits #12723
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
Open
lqiu96
wants to merge
10
commits into
main
Choose a base branch
from
migrate-auth-commits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
chore: Migrate auth commits #12723
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1994525
doc: Add Javadocs for setters in IdTokenCredentials.Builder (#1909)
lqiu96 0847925
fix: ImpersonatedCredentials does not use Calendar for expiration (#1…
lqiu96 b0dcca9
ci: GraalVM CI uses existing Truststore if configured (#1914)
lqiu96 90d185c
test: Fix sonatype complaints in the tests (#1870)
lqiu96 c27148b
fix(gdch): support EC private keys (#1896)
diegomarquezp 8f88c89
chore: Refactor x509Provider to create a shared Utils class for Mtls …
vverman 5baac2d
chore: Resolve merged conflicts
lqiu96 317e8b7
chore: Fix lint issues
lqiu96 3c4e47a
chore: Add licence with year for old TestEnvironmentProvider class
lqiu96 410e7bb
chore: Remove the new .kokoro/build.sh file added from split repo
lqiu96 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| #!/bin/bash | ||
| # Copyright 2019 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -eo pipefail | ||
|
|
||
| ## Get the directory of the build script | ||
| scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) | ||
| ## cd to the parent directory, i.e. the root of the git repo | ||
| cd ${scriptDir}/.. | ||
|
|
||
| # include common functions | ||
| source ${scriptDir}/common.sh | ||
|
|
||
| # Print out Maven & Java version | ||
| mvn -version | ||
| echo ${JOB_TYPE} | ||
|
|
||
| # attempt to install 3 times with exponential backoff (starting with 10 seconds) | ||
| retry_with_backoff 3 10 \ | ||
| mvn install -B -V -ntp \ | ||
| -DskipTests=true \ | ||
| -Dclirr.skip=true \ | ||
| -Denforcer.skip=true \ | ||
| -Dmaven.javadoc.skip=true \ | ||
| -Dgcloud.download.skip=true \ | ||
| -T 1C | ||
|
|
||
| # if GOOGLE_APPLICATION_CREDENTIALS is specified as a relative path, prepend Kokoro root directory onto it | ||
| if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then | ||
| export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS}) | ||
| fi | ||
|
|
||
| RETURN_CODE=0 | ||
| set +e | ||
|
|
||
| case ${JOB_TYPE} in | ||
| test) | ||
| echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}" | ||
| mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT} | ||
| RETURN_CODE=$? | ||
| ;; | ||
| test-logging) | ||
| echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}" | ||
| mvn clean test -P '!slf4j2x,slf4j2x-test' -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT} | ||
| RETURN_CODE=$? | ||
| ;; | ||
| lint) | ||
| mvn com.spotify.fmt:fmt-maven-plugin:check -B -ntp | ||
| RETURN_CODE=$? | ||
| ;; | ||
| javadoc) | ||
| mvn javadoc:javadoc javadoc:test-javadoc -B -ntp | ||
| RETURN_CODE=$? | ||
| ;; | ||
| integration) | ||
| mvn -B ${INTEGRATION_TEST_ARGS} \ | ||
| -ntp \ | ||
| -Penable-integration-tests \ | ||
| -DtrimStackTrace=false \ | ||
| -Dclirr.skip=true \ | ||
| -Denforcer.skip=true \ | ||
| -Djacoco.skip=true \ | ||
| -fae \ | ||
| verify | ||
| RETURN_CODE=$? | ||
| ;; | ||
| graalvm) | ||
| # Run Unit and Integration Tests with Native Image | ||
| bash .kokoro/populate-secrets.sh | ||
| export GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/secret_manager/java-it-service-account" | ||
|
|
||
| # GraalVM Native Image ignores JAVA_TOOL_OPTIONS at runtime. If the CI environment | ||
| # injects a custom truststore (e.g., for a proxy) via JAVA_TOOL_OPTIONS, we need to | ||
| # extract it and pass it explicitly to the native executable. | ||
| TRUST_STORE="" | ||
| if [[ "${JAVA_TOOL_OPTIONS}" =~ -Djavax.net.ssl.trustStore=([^ ]+) ]]; then | ||
| TRUST_STORE="${BASH_REMATCH[1]}" | ||
| fi | ||
|
|
||
| # We use 'package' instead of 'test' to build the native image without automatically | ||
| # running it via the Maven plugin. This allows us to run it manually with the | ||
| # extracted truststore argument in the next step, avoiding complex Maven XML overrides. | ||
| mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Pnative-test -Pslf4j2x package -pl 'oauth2_http' | ||
|
|
||
| # Run the native tests manually with the truststore | ||
| CMD="./oauth2_http/target/native-tests --xml-output-dir ./oauth2_http/target/native-test-reports" | ||
| if [ -n "$TRUST_STORE" ]; then | ||
| CMD="$CMD -Djavax.net.ssl.trustStore=$TRUST_STORE" | ||
| fi | ||
|
|
||
| echo "Executing: $CMD" | ||
| $CMD | ||
| RETURN_CODE=$? | ||
| ;; | ||
| samples) | ||
| SAMPLES_DIR=samples | ||
| # only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise. | ||
| if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]] | ||
| then | ||
| SAMPLES_DIR=samples/snapshot | ||
| fi | ||
|
|
||
| if [[ -f ${SAMPLES_DIR}/pom.xml ]] | ||
| then | ||
| for FILE in ${KOKORO_GFILE_DIR}/secret_manager/*-samples-secrets; do | ||
lqiu96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [[ -f "$FILE" ]] || continue | ||
| source "$FILE" | ||
| done | ||
|
|
||
| pushd ${SAMPLES_DIR} | ||
| mvn -B \ | ||
| -ntp \ | ||
| -DtrimStackTrace=false \ | ||
| -Dclirr.skip=true \ | ||
| -Denforcer.skip=true \ | ||
| -fae \ | ||
| verify | ||
| RETURN_CODE=$? | ||
| popd | ||
| else | ||
| echo "no sample pom.xml found - skipping sample tests" | ||
| fi | ||
| ;; | ||
| clirr) | ||
| mvn -B -ntp -Denforcer.skip=true clirr:check | ||
| RETURN_CODE=$? | ||
| ;; | ||
| *) | ||
| ;; | ||
| esac | ||
|
|
||
| if [ "${REPORT_COVERAGE}" == "true" ] | ||
| then | ||
| bash ${KOKORO_GFILE_DIR}/codecov.sh | ||
| fi | ||
|
|
||
| # fix output location of logs | ||
| bash .kokoro/coerce_logs.sh | ||
|
|
||
| if [[ "${ENABLE_FLAKYBOT}" == "true" ]] | ||
| then | ||
| chmod +x ${KOKORO_GFILE_DIR}/linux_amd64/flakybot | ||
| ${KOKORO_GFILE_DIR}/linux_amd64/flakybot -repo=googleapis/google-auth-library-java | ||
| fi | ||
|
|
||
| echo "exiting with ${RETURN_CODE}" | ||
| exit ${RETURN_CODE} | ||
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
140 changes: 140 additions & 0 deletions
140
google-auth-library-java/oauth2_http/java/com/google/auth/mtls/MtlsUtils.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package com.google.auth.mtls; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.auth.oauth2.EnvironmentProvider; | ||
| import com.google.auth.oauth2.PropertyProvider; | ||
| import com.google.common.base.Strings; | ||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Utility class for mTLS related operations. | ||
| * | ||
| * <p>For internal use only. | ||
| */ | ||
| @InternalApi | ||
| public class MtlsUtils { | ||
| static final String CERTIFICATE_CONFIGURATION_ENV_VARIABLE = "GOOGLE_API_CERTIFICATE_CONFIG"; | ||
| static final String WELL_KNOWN_CERTIFICATE_CONFIG_FILE = "certificate_config.json"; | ||
| static final String CLOUDSDK_CONFIG_DIRECTORY = "gcloud"; | ||
|
|
||
| private MtlsUtils() { | ||
| // Prevent instantiation for Utility class | ||
| } | ||
|
|
||
| /** | ||
| * Returns the path to the client certificate file specified by the loaded workload certificate | ||
| * configuration. | ||
| * | ||
| * @return The path to the certificate file. | ||
| * @throws IOException if the certificate configuration cannot be found or loaded. | ||
| */ | ||
| public static String getCertificatePath( | ||
| EnvironmentProvider envProvider, PropertyProvider propProvider, String certConfigPathOverride) | ||
| throws IOException { | ||
| String certPath = | ||
| getWorkloadCertificateConfiguration(envProvider, propProvider, certConfigPathOverride) | ||
| .getCertPath(); | ||
| if (Strings.isNullOrEmpty(certPath)) { | ||
| throw new CertificateSourceUnavailableException( | ||
| "Certificate configuration loaded successfully, but does not contain a 'certificate_file' path."); | ||
| } | ||
| return certPath; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves and loads the workload certificate configuration. | ||
| * | ||
| * <p>The configuration file is resolved in the following order of precedence: 1. The provided | ||
| * certConfigPathOverride (if not null). 2. The path specified by the | ||
| * GOOGLE_API_CERTIFICATE_CONFIG environment variable. 3. The well-known certificate configuration | ||
| * file in the gcloud config directory. | ||
| * | ||
| * @param envProvider the environment provider to use for resolving environment variables | ||
| * @param propProvider the property provider to use for resolving system properties | ||
| * @param certConfigPathOverride optional override path for the configuration file | ||
| * @return the loaded WorkloadCertificateConfiguration | ||
| * @throws IOException if the configuration file cannot be found, read, or parsed | ||
| */ | ||
| static WorkloadCertificateConfiguration getWorkloadCertificateConfiguration( | ||
| EnvironmentProvider envProvider, PropertyProvider propProvider, String certConfigPathOverride) | ||
| throws IOException { | ||
| File certConfig; | ||
| if (certConfigPathOverride != null) { | ||
| certConfig = new File(certConfigPathOverride); | ||
| } else { | ||
| String envCredentialsPath = envProvider.getEnv(CERTIFICATE_CONFIGURATION_ENV_VARIABLE); | ||
| if (!Strings.isNullOrEmpty(envCredentialsPath)) { | ||
| certConfig = new File(envCredentialsPath); | ||
| } else { | ||
| certConfig = getWellKnownCertificateConfigFile(envProvider, propProvider); | ||
| } | ||
| } | ||
|
|
||
| if (!certConfig.isFile()) { | ||
| throw new CertificateSourceUnavailableException( | ||
| "Certificate configuration file does not exist or is not a file: " | ||
| + certConfig.getAbsolutePath()); | ||
| } | ||
| try (InputStream certConfigStream = new FileInputStream(certConfig)) { | ||
| return WorkloadCertificateConfiguration.fromCertificateConfigurationStream(certConfigStream); | ||
| } | ||
| } | ||
|
|
||
| private static File getWellKnownCertificateConfigFile( | ||
| EnvironmentProvider envProvider, PropertyProvider propProvider) throws IOException { | ||
| File cloudConfigPath; | ||
| String envPath = envProvider.getEnv("CLOUDSDK_CONFIG"); | ||
| if (envPath != null) { | ||
| cloudConfigPath = new File(envPath); | ||
| } else { | ||
| String osName = propProvider.getProperty("os.name", "").toLowerCase(Locale.US); | ||
| if (osName.indexOf("windows") >= 0) { | ||
| String appData = envProvider.getEnv("APPDATA"); | ||
| if (Strings.isNullOrEmpty(appData)) { | ||
| throw new CertificateSourceUnavailableException( | ||
| "APPDATA environment variable is not set on Windows."); | ||
| } | ||
| File appDataPath = new File(appData); | ||
| cloudConfigPath = new File(appDataPath, CLOUDSDK_CONFIG_DIRECTORY); | ||
| } else { | ||
| File configPath = new File(propProvider.getProperty("user.home", ""), ".config"); | ||
| cloudConfigPath = new File(configPath, CLOUDSDK_CONFIG_DIRECTORY); | ||
| } | ||
| } | ||
| return new File(cloudConfigPath, WELL_KNOWN_CERTIFICATE_CONFIG_FILE); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.