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

Support passive environmental service account authentication in Google Cloud #1720

Merged
merged 4 commits into from
Nov 13, 2020
Merged

Conversation

voutilad
Copy link
Contributor

This PR adds the ability to leverage passive authentication if Neo4j is running in Google Cloud, like in the case of running in GCE on a VM host or as a container instance. This simplifies and improves APOC's Google Cloud Storage support by:

  • not requiring users to generate private key files for authenticating as a service account, which is generally frowned upon because they do not expire and are hard to track.
  • fixes a fundamental logic error causing NullPointerExceptions preventing accessing Google Storage objects (due to calling getHost() and not getAuthority() on the URI instance)
  • updates the docs accordingly for the new authenticationType options (NONE, PRIVATE_KEY, GCP_ENVIRONMENT)
    • PRIVATE_KEY replaces the previous behavior used by SERVICE, i.e. using the GOOGLE_APPLICATION_CREDENTIALS approach of pointing the client libraries at the private key json on the file system
    • GCP_ENVIRONMENT lets the client libraries naturally identify the service account and fetch a token for authenticating with Cloud Storage

This PR supersedes #1718 (of which I will close).

Note: Ultimately this should be cherry-picked on the 4.2 branch when that's ready.

The call to the `getHost()` method on the `URI` instance returns null
for a GCS uri like `gs://my_bucket/my_object`. Checking the URI docs
from Oracle
(https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html)
we should be using `getAuthority()`.

This commit changes the method call resolving the NPE. I've manually
tested with a test case hitting a publicly accessible object in Google
Cloud Storage (since no unit tests exist).
Previously, we forced using service account private keys set using the
GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a
generated json private key. This isn't required in native GCP
environments as the official Google Cloud clients will identify if
they're running in a GCP service (e.g. GAE, CloudRun, GCE, etc.) and
provide automatic authentication as a service account.

This change adds a new "authenticationType" and renames the old type:

- SERVICE becomes PRIVATE_KEY to explicitly describe that it's expecting
  to use a private key file.
- GCP_ENVIRONMENT is added to be used when running in GCP.

The logic is that for PRIVATE_KEY usage we still check the environment
for a set GOOGLE_APPLICATION_CREDENTIALS value. A runtime error is
thrown if it's not set.

For GCP_ENVIRONMENT, the environment check is ignored as the Google
client library will take care of validation.
Add in details on the new authentication types and behavior, replacing
the old settings. Tweak some verbiage.
Copy link
Contributor

@sarmbruster sarmbruster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me.

@sarmbruster sarmbruster merged commit e17336b into neo4j-contrib:4.1 Nov 13, 2020
sarmbruster pushed a commit that referenced this pull request Nov 13, 2020
…e Cloud (#1720)

* Fix broken GCS support that's throwing NPEs

The call to the `getHost()` method on the `URI` instance returns null
for a GCS uri like `gs://my_bucket/my_object`. Checking the URI docs
from Oracle
(https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html)
we should be using `getAuthority()`.

This commit changes the method call resolving the NPE. I've manually
tested with a test case hitting a publicly accessible object in Google
Cloud Storage (since no unit tests exist).

* fix typo in Google Cloud doc url

* Support GCP environmental service account auth

Previously, we forced using service account private keys set using the
GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a
generated json private key. This isn't required in native GCP
environments as the official Google Cloud clients will identify if
they're running in a GCP service (e.g. GAE, CloudRun, GCE, etc.) and
provide automatic authentication as a service account.

This change adds a new "authenticationType" and renames the old type:

- SERVICE becomes PRIVATE_KEY to explicitly describe that it's expecting
  to use a private key file.
- GCP_ENVIRONMENT is added to be used when running in GCP.

The logic is that for PRIVATE_KEY usage we still check the environment
for a set GOOGLE_APPLICATION_CREDENTIALS value. A runtime error is
thrown if it's not set.

For GCP_ENVIRONMENT, the environment check is ignored as the Google
client library will take care of validation.

* Update Google Cloud documentation for new auth

Add in details on the new authentication types and behavior, replacing
the old settings. Tweak some verbiage.
mneedham pushed a commit that referenced this pull request Nov 13, 2020
…e Cloud (#1720)

* Fix broken GCS support that's throwing NPEs

The call to the `getHost()` method on the `URI` instance returns null
for a GCS uri like `gs://my_bucket/my_object`. Checking the URI docs
from Oracle
(https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html)
we should be using `getAuthority()`.

This commit changes the method call resolving the NPE. I've manually
tested with a test case hitting a publicly accessible object in Google
Cloud Storage (since no unit tests exist).

* fix typo in Google Cloud doc url

* Support GCP environmental service account auth

Previously, we forced using service account private keys set using the
GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a
generated json private key. This isn't required in native GCP
environments as the official Google Cloud clients will identify if
they're running in a GCP service (e.g. GAE, CloudRun, GCE, etc.) and
provide automatic authentication as a service account.

This change adds a new "authenticationType" and renames the old type:

- SERVICE becomes PRIVATE_KEY to explicitly describe that it's expecting
  to use a private key file.
- GCP_ENVIRONMENT is added to be used when running in GCP.

The logic is that for PRIVATE_KEY usage we still check the environment
for a set GOOGLE_APPLICATION_CREDENTIALS value. A runtime error is
thrown if it's not set.

For GCP_ENVIRONMENT, the environment check is ignored as the Google
client library will take care of validation.

* Update Google Cloud documentation for new auth

Add in details on the new authentication types and behavior, replacing
the old settings. Tweak some verbiage.
mneedham pushed a commit that referenced this pull request Nov 19, 2020
…e Cloud (#1720)

* Fix broken GCS support that's throwing NPEs

The call to the `getHost()` method on the `URI` instance returns null
for a GCS uri like `gs://my_bucket/my_object`. Checking the URI docs
from Oracle
(https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html)
we should be using `getAuthority()`.

This commit changes the method call resolving the NPE. I've manually
tested with a test case hitting a publicly accessible object in Google
Cloud Storage (since no unit tests exist).

* fix typo in Google Cloud doc url

* Support GCP environmental service account auth

Previously, we forced using service account private keys set using the
GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a
generated json private key. This isn't required in native GCP
environments as the official Google Cloud clients will identify if
they're running in a GCP service (e.g. GAE, CloudRun, GCE, etc.) and
provide automatic authentication as a service account.

This change adds a new "authenticationType" and renames the old type:

- SERVICE becomes PRIVATE_KEY to explicitly describe that it's expecting
  to use a private key file.
- GCP_ENVIRONMENT is added to be used when running in GCP.

The logic is that for PRIVATE_KEY usage we still check the environment
for a set GOOGLE_APPLICATION_CREDENTIALS value. A runtime error is
thrown if it's not set.

For GCP_ENVIRONMENT, the environment check is ignored as the Google
client library will take care of validation.

* Update Google Cloud documentation for new auth

Add in details on the new authentication types and behavior, replacing
the old settings. Tweak some verbiage.
conker84 pushed a commit to conker84/neo4j-apoc-procedures that referenced this pull request Mar 29, 2021
…e Cloud (neo4j-contrib#1720)

* Fix broken GCS support that's throwing NPEs

The call to the `getHost()` method on the `URI` instance returns null
for a GCS uri like `gs://my_bucket/my_object`. Checking the URI docs
from Oracle
(https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html)
we should be using `getAuthority()`.

This commit changes the method call resolving the NPE. I've manually
tested with a test case hitting a publicly accessible object in Google
Cloud Storage (since no unit tests exist).

* fix typo in Google Cloud doc url

* Support GCP environmental service account auth

Previously, we forced using service account private keys set using the
GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a
generated json private key. This isn't required in native GCP
environments as the official Google Cloud clients will identify if
they're running in a GCP service (e.g. GAE, CloudRun, GCE, etc.) and
provide automatic authentication as a service account.

This change adds a new "authenticationType" and renames the old type:

- SERVICE becomes PRIVATE_KEY to explicitly describe that it's expecting
  to use a private key file.
- GCP_ENVIRONMENT is added to be used when running in GCP.

The logic is that for PRIVATE_KEY usage we still check the environment
for a set GOOGLE_APPLICATION_CREDENTIALS value. A runtime error is
thrown if it's not set.

For GCP_ENVIRONMENT, the environment check is ignored as the Google
client library will take care of validation.

* Update Google Cloud documentation for new auth

Add in details on the new authentication types and behavior, replacing
the old settings. Tweak some verbiage.
conker84 pushed a commit that referenced this pull request Apr 12, 2021
…e Cloud (#1720)

* Fix broken GCS support that's throwing NPEs

The call to the `getHost()` method on the `URI` instance returns null
for a GCS uri like `gs://my_bucket/my_object`. Checking the URI docs
from Oracle
(https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html)
we should be using `getAuthority()`.

This commit changes the method call resolving the NPE. I've manually
tested with a test case hitting a publicly accessible object in Google
Cloud Storage (since no unit tests exist).

* fix typo in Google Cloud doc url

* Support GCP environmental service account auth

Previously, we forced using service account private keys set using the
GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a
generated json private key. This isn't required in native GCP
environments as the official Google Cloud clients will identify if
they're running in a GCP service (e.g. GAE, CloudRun, GCE, etc.) and
provide automatic authentication as a service account.

This change adds a new "authenticationType" and renames the old type:

- SERVICE becomes PRIVATE_KEY to explicitly describe that it's expecting
  to use a private key file.
- GCP_ENVIRONMENT is added to be used when running in GCP.

The logic is that for PRIVATE_KEY usage we still check the environment
for a set GOOGLE_APPLICATION_CREDENTIALS value. A runtime error is
thrown if it's not set.

For GCP_ENVIRONMENT, the environment check is ignored as the Google
client library will take care of validation.

* Update Google Cloud documentation for new auth

Add in details on the new authentication types and behavior, replacing
the old settings. Tweak some verbiage.
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

Successfully merging this pull request may close these issues.

2 participants