Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/cloud/internal/oauth2_external_account_credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class ExternalAccountCredentials : public oauth2_internal::Credentials {
StatusOr<AccessToken> GetToken(
std::chrono::system_clock::time_point tp) override;

StatusOr<std::string> universe_domain() const override {
return info_.universe_domain;
}

StatusOr<std::string> universe_domain(Options const&) const override {
return info_.universe_domain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,9 +1504,11 @@ TEST(ExternalAccountAuthorizedUser, Working) {
ASSERT_STATUS_OK(access_token);
EXPECT_EQ(access_token->expiration, now + expected_expires_in);
EXPECT_EQ(access_token->token, expected_access_token);
auto ud = credentials.universe_domain(Options{});
StatusOr<std::string> ud = credentials.universe_domain(Options{});
ASSERT_STATUS_OK(ud);
EXPECT_EQ(*ud, "my-domain.net");
EXPECT_THAT(credentials.universe_domain(),
testing_util::IsOkAndHolds("my-domain.net"));
}

TEST(ExternalAccountAuthorizedUser, WorkingWithRefreshTokenRotation) {
Expand Down
24 changes: 21 additions & 3 deletions google/cloud/internal/oauth2_google_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "google/cloud/internal/oauth2_service_account_credentials.h"
#include "google/cloud/internal/parse_service_account_p12_file.h"
#include "google/cloud/internal/throw_delegate.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include <nlohmann/json.hpp>
#include <fstream>
#include <iterator>
Expand Down Expand Up @@ -69,12 +71,28 @@ StatusOr<std::unique_ptr<Credentials>> LoadCredsFromString(
std::move(client_factory)));
}
if (cred_type == "impersonated_service_account") {
auto info = ParseImpersonatedServiceAccountCredentials(contents, path);
StatusOr<ImpersonatedServiceAccountCredentialsInfo> info =
ParseImpersonatedServiceAccountCredentials(contents, path);
if (!info) return std::move(info).status();
auto source_creds = LoadCredsFromString(std::move(info->source_credentials),
path, options, client_factory);
StatusOr<std::unique_ptr<Credentials>> source_creds = LoadCredsFromString(
std::move(info->source_credentials), path, options, client_factory);
if (!source_creds) return std::move(source_creds).status();

StatusOr<std::string> source_universe_domain =
(*source_creds)->universe_domain(options);
if (!source_universe_domain) {
return std::move(source_universe_domain).status();
}
if (!absl::EqualsIgnoreCase(*source_universe_domain,
info->universe_domain)) {
return internal::InvalidArgumentError(
absl::StrCat("Universe domain mismatch between impersonated "
"credentials (",
info->universe_domain, ") and source credentials (",
*source_universe_domain, ") on data from ", path),
GCP_ERROR_INFO());
}

auto opts = options;
auto& delegates = opts.lookup<DelegatesOption>();
for (auto& delegate : info->delegates) {
Expand Down
Loading
Loading