Skip to content
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

ProjectId override question #979

Closed
fondberg opened this issue May 3, 2016 · 4 comments
Closed

ProjectId override question #979

fondberg opened this issue May 3, 2016 · 4 comments
Assignees

Comments

@fondberg
Copy link

fondberg commented May 3, 2016

After following the procedures outlined in the README (here) for creating a service account for machine integration the projectId is correctly set in the json key file however the usage of it is not.

I have two questions that I hope I can get help with:

  • When changing the project_id in code some project which is wrong it still works. Can someone explain if the gcloud-java or the Google Cloud service stores or parses the service account to extract the correct project_id?
Storage storage = StorageOptions.builder() 
  .authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
  .projectId("projectDoesNotExist") // <---- HERE
  .build()
  .service();
// It is possible to use the Storage.writer and upload correctly to the service accounts project_id!!!
  • Reading Specifying a Project ID there are various ways to set the project id, however none using the following flow from code. Question is if it would be good if the StorageOptions.builder() could take a file String as argument?
//Todays API
Storage storage = StorageOptions.builder() 
  .authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
  .build()
  .service();
//here the project_id of StorageOptions is never set if no environment variable is set as the json project_id is never parsed
//Proposed API change which automatically uses AuthCredentials is the json file is supplied
Storage storage = StorageOptions.builder("/path/to/my/key.json") 
  .build()
  .service();
@mziccard
Copy link
Contributor

mziccard commented May 3, 2016

Hi @fonzy2013, thanks for the report!

When changing the project_id in code some project which is wrong it still works. Can someone explain if the gcloud-java or the Google Cloud service stores or parses the service account to extract the correct project_id?

As written in the README the projectId provided with projectId("...") has priority over any other possible projectId. So, in your snippet, we are actually using the wrong projectDoesNotExist id. What is happening here is that in Storage a bucket name must be unique across the entire Cloud Storage namespace (not only in your project). So all operations inside a bucket (creating, getting, listing blobs) do not require (nor allow) us to pass the projectId (since the bucket is already enough to uniquely define where to apply the operation). Hence no checks are made by the service on the projectId for that operation, but clearly the service account you provided to StorageOptions is checked to see if you have rights to access the bucket.

On the other hand, as you probably already noticed, project id is used to create and list buckets (to define the project that owns the bucket - and that should be billed for it). So if you provide a wrong project id to StorageOptions the operations create(BucketInfo) and list() will fail.

Question is if it would be good if the StorageOptions.builder() could take a file String as argument?

We considered having AuthCredentials.createForJson("/path/to/my/key.json") but that would not be supported in all platforms (i.e. AppEngine). So we decided to stick to the stream version as creating a stream from a file path should be easy enough.

Hope this answers your doubts.

@fondberg
Copy link
Author

fondberg commented May 9, 2016

I have now read the code and tested further.
My result is the following:

  • ProjectId MUST be set when building the service with .projectId("my-project"), otherwise it fails. This can however be solved easily with providing the project when building the service BUT we still feel it would be better to have the API use the one from the json file
  • After a successful login there are NO way to change the project for the service account. This we do consider as a bug but is probably not something that can be fixed in this API, correct?

Are these reflections correct?

@mziccard
Copy link
Contributor

mziccard commented May 9, 2016

ProjectId MUST be set when building the service with .projectId("my-project"), otherwise it fails. This can however be solved easily with providing the project when building the service BUT we still feel it would be better to have the API use the one from the json file

Did you consider using the GOOGLE_APPLICATION_CREDENTIALS env variable and make it point to your JSON key? This way the project id will be read from the json file

After a successful login there are NO way to change the project for the service account. This we do consider as a bug but is probably not something that can be fixed in this API, correct?

This is unclear to me. What do you mean with "login" and "service account"?

@mziccard
Copy link
Contributor

I am closing this as it has remained open for 2 months without answers. Feel free to reopen it with more details if need be.

github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this issue Jun 29, 2022
…oogleapis#979)

- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 457524730

Source-Link: googleapis/googleapis@917e7f2

Source-Link: https://github.com/googleapis/googleapis-gen/commit/2497f9a069d3f6b2d6810d5a4e239cda1e7e5a39
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMjQ5N2Y5YTA2OWQzZjZiMmQ2ODEwZDVhNGUyMzljZGExZTdlNWEzOSJ9
github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this issue Jul 1, 2022
🤖 I have created a release *beep* *boop*
---


## [3.0.0](googleapis/java-aiplatform@v2.9.8...v3.0.0) (2022-07-01)


### ⚠ BREAKING CHANGES

* added packaging options for C#, Ruby, and PHP

### Features

* add BatchImportModelEvaluationSlices API in aiplatform v1 model_service.proto ([googleapis#972](googleapis/java-aiplatform#972)) ([7f45b24](googleapis/java-aiplatform@7f45b24))
* add BatchImportModelEvaluationSlices API in aiplatform v1beta1 model_service.proto ([7f45b24](googleapis/java-aiplatform@7f45b24))
* add display_name and metadata to ModelEvaluation in aiplatform model_evaluation.proto ([a2a404f](googleapis/java-aiplatform@a2a404f))
* add ListSavedQueries rpc to aiplatform v1 dataset_service.proto ([googleapis#975](googleapis/java-aiplatform#975)) ([ab9ba69](googleapis/java-aiplatform@ab9ba69))
* add ListSavedQueries rpc to aiplatform v1beta1 dataset_service.proto ([ab9ba69](googleapis/java-aiplatform@ab9ba69))
* add model_monitoring_config to BatchPredictionJob in aiplatform v1beta1 batch_prediction_job.proto ([googleapis#892](googleapis/java-aiplatform#892)) ([a2a404f](googleapis/java-aiplatform@a2a404f))
* add model_version_id to BatchPredictionJob in aiplatform v1 batch_prediction_job.proto ([7f45b24](googleapis/java-aiplatform@7f45b24))
* add model_version_id to DeployedModel in aiplatform v1 endpoint.proto ([7f45b24](googleapis/java-aiplatform@7f45b24))
* add model_version_id to PredictResponse in aiplatform v1 prediction_service.proto ([7f45b24](googleapis/java-aiplatform@7f45b24))
* add saved_query_id to InputDataConfig in aiplatform v1 training_pipeline.proto ([ab9ba69](googleapis/java-aiplatform@ab9ba69))
* add saved_query_id to InputDataConfig in aiplatform v1beta1 training_pipeline.proto ([ab9ba69](googleapis/java-aiplatform@ab9ba69))
* add saved_query.proto to aiplatform v1 ([ab9ba69](googleapis/java-aiplatform@ab9ba69))
* add saved_query.proto to aiplatform v1beta1 ([ab9ba69](googleapis/java-aiplatform@ab9ba69))
* add template_metadata to PipelineJob in aiplatform v1beta1 pipeline_job.proto ([a2a404f](googleapis/java-aiplatform@a2a404f))
* **samples:** add create-featurestore sample ([googleapis#948](googleapis/java-aiplatform#948)) ([ffc4b87](googleapis/java-aiplatform@ffc4b87))


### Bug Fixes

* added packaging options for C#, Ruby, and PHP ([a2a404f](googleapis/java-aiplatform@a2a404f))
* update gapic-generator-java with mock service generation fixes ([googleapis#979](googleapis/java-aiplatform#979)) ([e5f3ca5](googleapis/java-aiplatform@e5f3ca5))


### Dependencies

* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.13.0 ([googleapis#973](googleapis/java-aiplatform#973)) ([56ad705](googleapis/java-aiplatform@56ad705))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
github-actions bot pushed a commit that referenced this issue Aug 9, 2022
…979)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-core](https://github.com/googleapis/java-core) | `2.8.7` -> `2.8.8` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.8/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.8/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.8/compatibility-slim/2.8.7)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.8/confidence-slim/2.8.7)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/java-core</summary>

### [`v2.8.8`](https://github.com/googleapis/java-core/blob/HEAD/CHANGELOG.md#&#8203;288-httpsgithubcomgoogleapisjava-corecomparev287v288-2022-08-04)

[Compare Source](https://github.com/googleapis/java-core/compare/v2.8.7...v2.8.8)

##### Dependencies

-   update dependency com.google.errorprone:error_prone_annotations to v2.15.0 ([#&#8203;897](https://github.com/googleapis/java-core/issues/897)) ([29e4fc9](https://github.com/googleapis/java-core/commit/29e4fc93d5d4d50f7de85eae7a8150314cca6f43))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-dialogflow).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xNDMuMSIsInVwZGF0ZWRJblZlciI6IjMyLjE0My4xIn0=-->
github-actions bot pushed a commit that referenced this issue Aug 9, 2022
🤖 I have created a release *beep* *boop*
---


## [4.8.0](googleapis/java-dialogflow@v4.7.5...v4.8.0) (2022-08-05)


### Features

* deprecated the filter field and add resource_definition ([d58232f](googleapis/java-dialogflow@d58232f))
* provide new parameter cx_current_page, the unique identifier of the CX page to override the `current_page` in the session. Add filter field to ListAnswerRecordsRequest. And add AudioInput to analysis requests ([d58232f](googleapis/java-dialogflow@d58232f))


### Dependencies

* update dependency com.google.cloud:google-cloud-core to v2.8.8 ([#979](googleapis/java-dialogflow#979)) ([aee2eab](googleapis/java-dialogflow@aee2eab))


### Documentation

* add more meaningful comments ([d58232f](googleapis/java-dialogflow@d58232f))
* add more meaningful comments ([d58232f](googleapis/java-dialogflow@d58232f))
* added an explicit note that DetectIntentRequest's text input is limited by 256 characters ([d58232f](googleapis/java-dialogflow@d58232f))
* **owlbot-java:** explaining why not using formatter in pom.xml ([#1511](https://github.com/googleapis/java-dialogflow/issues/1511)) ([#973](googleapis/java-dialogflow#973)) ([3202efe](googleapis/java-dialogflow@3202efe)), closes [#1502](https://github.com/googleapis/java-dialogflow/issues/1502)
* updated some method comments and added an explicit note that DetectIntentRequest's text input is limited by 256 characters ([#954](googleapis/java-dialogflow#954)) ([d58232f](googleapis/java-dialogflow@d58232f))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
github-actions bot pushed a commit that referenced this issue Sep 15, 2022
…ator_java versions (#979)

- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 472750037

Source-Link: googleapis/googleapis@88f2ea3

Source-Link: googleapis/googleapis-gen@230a558
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMjMwYTU1ODgzMDZhYWUxOGZlOGYyYTU3ZjE0ZDQwMzlhZDcyYzkwMSJ9
github-actions bot pushed a commit that referenced this issue Sep 15, 2022
…ator_java versions (#979)

- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 472750037

Source-Link: googleapis/googleapis@88f2ea3

Source-Link: googleapis/googleapis-gen@230a558
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMjMwYTU1ODgzMDZhYWUxOGZlOGYyYTU3ZjE0ZDQwMzlhZDcyYzkwMSJ9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants