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 — Stackdriver logging - setCredentials not working, getting "PERMISSION_DENIED: The caller does not have permission" · Issue #3170 · googleapis/google-cloud-java

Stackdriver logging - setCredentials not working, getting "PERMISSION_DENIED: The caller does not have permission" #3170

New issue
Copy link
New issue
Copy link
Closed
Closed
Stackdriver logging - setCredentials not working, getting "PERMISSION_DENIED: The caller does not have permission"#3170
Copy link
Assignees
yihanzhen
Labels
authpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@petergeneric
petergeneric
opened on Apr 19, 2018
Issue body actions

I'm trying to use setCredentials in LoggingBuilder, however if I supply my key.json file from code I'm getting PERMISSION_DENIED on my logging call.

If I instead populate the environment variable GOOGLE_APPLICATION_CREDENTIALS with the same /path/to/key.json it works.

My main method is:

		Logging logging = LoggingOptions
				                  .newBuilder()
				                  .setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream("/path/to/key.json")))
				                  .build()
				                  .getService();

		logging.setWriteSynchronicity(Synchronicity.SYNC);

		logging.setFlushSeverity(Severity.DEBUG);

		LogEntry entry = LogEntry
				                 .newBuilder(Payload.StringPayload.of("Hello world"))
				                 .setSeverity(Severity.INFO)
				                 .setLogName("test-log")
				                 .setResource(MonitoredResource
						                              .newBuilder("global")
						                              .build())
				                 .build();

		logging.write(Collections.singleton(entry)); // Throws PERMISSION_DENIED

My only dependencies:

		<dependency>
			<groupId>com.google.cloud</groupId>
			<artifactId>google-cloud-logging</artifactId>
			<version>1.26.0</version>
		</dependency>
Reacted by Joey Berglund

Activity

  1. jberglund-BSFT commented on May 16, 2018

    @jberglund-BSFT
    jberglund-BSFT
    on May 16, 2018
    More actions

    I'm seeing the same issue. I am using a project admin service account that has the roles/logging.logWriter role.

  2. pongad commented on May 21, 2018

    @pongad
    pongad
    on May 21, 2018
    Contributor
    More actions

    Hmm! Assuming you're on Unix-like environment, could you run

    <$GOOGLE_APPLICATION_CREDENTIALS grep type

    ?

    The JSON files have two different kinds, "service_account" and "authorized_user". If the type is authorized_user, that'd explain why you're seeing this problem.

    To fix, you could use com.google.auth.oauth2.GoogleCredentials.fromStream instead. I believe that method is used to read GOOGLE_APPLICATION_CREDENTIALS file behind the scenes, so it'd be surprising if that doesn't work.

  3. pongad
    added
    type: questionRequest for information or clarification. Not an issue.
    auth
    on May 21, 2018
  4. petergeneric commented on May 22, 2018

    @petergeneric
    petergeneric
    on May 22, 2018
    Author
    More actions

    "type": "service_account"

    Same issue with ServiceAccountCredentials.fromStream and GoogleCredentials.fromStream, also updated the test against version 1.30.0 and no change. Still works perfectly if I set an environment variable instead.

    I poked around inside the library by setting a breakpoint at ClientCalls.onClose - looking at the callOptions of the call, credentials appeared to be set up exactly the same for both environment variable and ServiceAccountCredentials.fromStream approaches.

  5. pongad
    self-assigned this
    on May 22, 2018
  6. pongad commented on May 30, 2018

    @pongad
    pongad
    on May 30, 2018
    Contributor
    More actions

    I am not able to reproduce the original issue. In all cases, setting the env var and using ServiceAccountCredentials behave the same way. If they are set to the same file, they either both work or both fail.

    @petergeneric Is there any chance you have gcloud installed on your machine? For some reason, the gcloud command seems to confuse the auth lib. I had to gcloud auth revoke before things start working. This should also be investigated.

  7. petergeneric commented on May 30, 2018

    @petergeneric
    petergeneric
    on May 30, 2018
    Author
    More actions

    Aha! I figured out what is going on - gcloud auth revoke didn't work, but when I blew away ~/.config/gcloud it started complaining about a Project ID not being set - when I set it on the LoggingOptions.Builder everything worked... so I think what was happening is that the default project was being implicitly picked up from ~/.config/gcloud/configurations/config_default and used with the credentials json file I was explicitly specifying (and my default project for gcloud is different from this testing project for logging, which explains the permission denied error).

    So perhaps a little too much magic going on in the library despite me trying to set things up manually!

    I set up a simplified test-case at https://github.com/petergeneric/gcloud-logging-testcase but I don't think that's of any use at this point now that we've figured out the underlying issue. I'm happy to close this issue, since it's probably classified as working as intended!

  8. pongad commented on May 31, 2018

    @pongad
    pongad
    on May 31, 2018
    Contributor
    More actions

    @petergeneric I would actually classify this as bug for "unnecessary confusing auth behavior", but I'll lower this down to P2.

  9. pongad
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    and removed
    type: questionRequest for information or clarification. Not an issue.
    on May 31, 2018
  10. pongad
    removed their assignment
    on Jun 4, 2018
  11. yihanzhen
    self-assigned this
    on Jun 6, 2018
  12. yihanzhen commented on Jun 14, 2018

    @yihanzhen
    yihanzhen
    on Jun 14, 2018
    Contributor
    More actions

    Seems the problem has been fixed here. @petergeneric I believe you can also use gcloud config set project to change projects if that's what is causing conflicts in your case. To folks who may see this issue in the future: we strongly encourage everyone to use the environment variable GOOGLE_APPLICATION_CREDENTIALS instead of gcloud auth login for authentication.

  13. yihanzhen
    closed this as completedon Jun 14, 2018
  14. theacodes
    unassigned
    yihanzhen
    on Sep 28, 2018
  15. JustinBeckwith
    assigned
    yihanzhen
    on Feb 1, 2021
  16. chingor13
    added 4 commits that reference this issue on Mar 24, 2026

    feat: expose property in GrpcTransportChannel if it uses direct path. (…

    b20cec6

    chore(main): release 2.46.0 (#3187)

    acc44b7

    chore: Update generation configuration at Wed Jun 25 15:48:09 UTC 2025 (

    d0d4980

    chore: manage hermetic_library_generation action version via Hermetic…

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

Metadata

Metadata

Assignees

  • @yihanzhen
    yihanzhen

Labels

authpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

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.