GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Wrong default project ID is chosen when active configuration is not the default or service keys are used · Issue #827 · googleapis/google-cloud-java

Wrong default project ID is chosen when active configuration is not the default or service keys are used #827

New issue
Copy link
New issue
Copy link
Closed
Closed
Wrong default project ID is chosen when active configuration is not the default or service keys are used#827
Copy link
Assignees
mziccard

Description

@tswast
tswast
opened on Mar 31, 2016
Issue body actions

Wrong gcloud command configuration is loaded

Problem

My ~/.config/gcloud/configurations/config_default contents:

[core]
account = ***REDACTED***@gmail.com
project = gcpnext2016-swast
[compute]
zone = us-central1-a
region = us-central1

My active configuration:

$ gcloud config list
Your active configuration is: [swast-test-flexible]
[app]
suppress_change_warning = true
[compute]
region = us-central1
zone = us-central1-b
[core]
account = [email protected]
disable_usage_reporting = False
project = swast-test-flexible
[metrics]
command_name = gcloud.config.list

When I run the Bookshelf application, which uses Application Default Credentials locally with mvn -Plocal clean jetty:run-exploded and I connect to http://localhost:8080, I see data from my gcpnext2016-swast project, not the swast-test-flexible project like I expect.

Steps to reproduce

  1. Run the Bookshelf application, which uses Application Default Credentials locally with mvn -Plocal clean jetty:run-exploded and I connect to http://localhost:8080
  2. Add a few books.
  3. Run gcloud init.
  4. Create a new configuration instead of modifying the default, and select a different project this time.
  5. Run the Bookshelf application again.
  6. Notice that you still see the same data from the project selected in the default configuration, not the new configuration that you just activated.

Suspected root cause

gcloud-java uses default configuration rather than the currently selected one to figure out which project to send RPCs to. https://github.com/GoogleCloudPlatform/gcloud-java/blob/d03e5a7d80dc17d9012476557015e4f44be64687/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java#L394

Project ID is not extracted from service keys

Problem

When I use a service key, with the Bookshelf app command

GOOGLE_APPLICATION_CREDENTIALS=$HOME/src/service-keys/swast-test-flexible.json mvn -Plocal clean jetty:run-exploded

I get an exception when my default gcloud command configuration has a different project ID than the service key.

Caused by: com.google.gcloud.datastore.DatastoreException: Unauthorized.

Steps to reproduce

  1. Create a JSON service key for a project (a different project than what the default gcloud command configuration is set to).
  2. Run the Bookshelf application using this service key.
    GOOGLE_APPLICATION_CREDENTIALS=path/to/key.json mvn -Plocal clean jetty:run-exploded
  3. Observe an unexpected com.google.gcloud.datastore.DatastoreException.

Suspected root cause

The defaultProjectId is not extracting the project information from the service key, as I would expect it to. Note that a key is of the format:

{
  "type": "service_account",
  "project_id": "swast-test-flexible",  <-- gcloud-java should be using this, but it's not.
  "private_key_id": "abcdedfghijklmnop",
  "private_key": "-----BEGIN PRIVATE KEY-----\nBLAHblahBLAH\n-----END PRIVATE KEY-----\n",
  "client_email": "getting-started-java-laptop@swast-test-flexible.iam.gserviceaccount.com",
  "client_id": "1234567890",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/getting-started-java-laptop%40swast-test-flexible.iam.gserviceaccount.com"
}

Activity

  1. pcostell commented on Mar 31, 2016

    @pcostell
    pcostell
    on Mar 31, 2016
    Contributor
    More actions

    Just a note here --

    The Datastore project you want to talk to is not necessarily the project that your service account is attached to. So gcloud-java shouldn't grab your service account from the key.

    However, it would be great if it could pull from the active project and not the default one from the cloud SDK.

  2. tswast commented on Mar 31, 2016

    @tswast
    tswast
    on Mar 31, 2016
    ContributorAuthor
    More actions

    @pcostell If I'm using a service account key, I would most definitely expect to be using that project by default. This is the way that Application Default Credentials are defined to work.

    I would expect the DATASTORE_ENV_NAME or PROJECT_ENV_NAME to be able to override this, but using the active gcloud configuration over the service account key is the wrong order for Application Default Credentials.

    CC @jerjou @lesv

  3. pcostell commented on Mar 31, 2016

    @pcostell
    pcostell
    on Mar 31, 2016
    Contributor
    More actions

    I'm not sure that's true. There is nothing in the ADC site which says it also sets your project ID that you want to connect to, only that it sets up which one you want to connect as.

  4. mziccard commented on Mar 31, 2016

    @mziccard
    mziccard
    on Mar 31, 2016
    Contributor
    More actions

    Thanks @tswast for the thorough report (I wish all issues where this detailed). I will look into this. Let me start with a couple of thoughts:

    Wrong gcloud command configuration is loaded

    You are right this must be fixed by loading the project ID from the active config.

    Project ID is not extracted from service keys

    I believe that the project_id field is a recent addition to the JSON credentials (I have ~4 months old JSON credentials without that field). If this is there to last I think we should use it (this should be notified to other gcloud-* maintainers). /cc @jgeewax @aozarov

  5. mziccard commented on Apr 4, 2016

    @mziccard
    mziccard
    on Apr 4, 2016
    Contributor
    More actions

    Good news:

    Wrong gcloud command configuration is loaded

    Was fixed in #831 and is included in gcloud-java 0.1.7

    Project ID is not extracted from service keys

    Was fixed in #845 and will be available in the next release

  6. mziccard
    closed this as completedon Apr 4, 2016
  7. tswast commented on Apr 4, 2016

    @tswast
    tswast
    on Apr 4, 2016
    ContributorAuthor
    More actions

    Thank you!

  8. JustinBeckwith
    assigned
    mziccard
    on Feb 1, 2021
  9. github-actions
    added 2 commits that reference this issue on Jun 29, 2022

    deps: update dependency io.github.bonigarcia:webdrivermanager to v5.2…

    7f0a96f

    chore(main): release 3.0.0 (googleapis#815)

    7dc20ab
  10. github-actions
    added a commit that references this issue on Jul 14, 2022

    chore: mark native image checks as required (#827)

    084ac98
  11. github-actions
    added 2 commits that reference this issue on Aug 9, 2022

    build(deps): update dependency com.google.cloud:google-cloud-shared-c…

    d6f063c

    chore(main): release 2.3.1 (#827)

    ab2b24c
  12. github-actions
    added 4 commits that reference this issue on Sep 15, 2022

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    3516add

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    bb42e07

    chore(main): release 2.3.3 (#828)

    b50afba

    chore(main): release 2.4.3 (#828)

    02b8b5f
  13. github-actions
    added 2 commits that reference this issue on Sep 30, 2022

    chore(main): release 2.5.5 (#828)

    b99c2fd

    chore(main): release 2.4.9 (#854)

    7420f3b
  14. github-actions
    added a commit that references this issue on Nov 9, 2022

    chore: delete deprecated samples (#827)

    f7aacad
  15. suztomo
    added 4 commits that reference this issue on Feb 1, 2023

    deps: update dependency com.google.api:api-common to v2.2.0 (#827)

    fa4a5db

    chore(main): release 2.7.0 (#809)

    e453afe

    deps: update dependency google-crc32c to v1.5.0 (#827)

    ee9e013

    chore(main): release 3.0.4 (#850)

    cf70e07
  16. meltsufin
    added a commit that references this issue on Dec 22, 2025

    build(deps): update dependency org.codehaus.mojo:build-helper-maven-p…

    9787884
  17. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore(main): release 0.126.6-SNAPSHOT (#827)

    2a3ed97
  18. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore(deps): update dependency com.google.cloud:google-cloud-datastor…

    eb93d44
  19. suztomo
    added a commit that references this issue on Mar 11, 2026

    build(deps): update dependency org.codehaus.mojo:build-helper-maven-p…

    aaf93fb
  20. benjaminp
    added a commit that references this issue on Jul 13, 2026

    chore: regenerate README (googleapis#827)

    92abbd2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.