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

Using ORAS from snap can't authenticate with gcloud credential helper #1079

Closed
1 task
jteichroeb-oanda opened this issue Aug 24, 2023 · 23 comments · Fixed by #1256, #1381 or armbian/build#6964 · May be fixed by jnnycn007/Armbian-build#20
Closed
1 task
Labels
bug Something isn't working GCP Google Cloud Platform related issues logging
Milestone

Comments

@jteichroeb-oanda
Copy link

What happened in your environment?

I'm using oras like this:
oras push us-central1-docker.pkg.dev/... file.tar.gz

I have docker configured to use gcloud auth using this command:
gcloud auth configure-docker us-central1-docker.pkg.dev

which sets up the ~/.docker/config.json like so:

{
  "credHelpers": {
    "us-central1-docker.pkg.dev": "gcloud"
  }
}

If I use oras from snap, authentication fails, but if I use the downloaded oras binary it works fine

What did you expect to happen?

Authentication doesn't depend on

How can we reproduce it?

Since this requires authenticating with google cloud platform, replicating my setup isn't the easiest. I can help someone setup a similar environment if necessary

What is the version of your ORAS CLI?

1.0.0, which is the latest version in snap

What is your OS environment?

Ubuntu 20.04

Are you willing to submit PRs to fix it?

  • Yes, I am willing to fix it.
@jteichroeb-oanda jteichroeb-oanda added the bug Something isn't working label Aug 24, 2023
@qweeah
Copy link
Contributor

qweeah commented Aug 25, 2023

Can you attach the debug log of failed oras push? You can get that with --debug flag set.

@jteichroeb-oanda
Copy link
Author

Here's the debug log, overall not the most helpful. I've redacted some URLs with [...]

DEBU[0000] Request #0
> Request URL: "https://us-central1-docker.pkg.dev/v2/[...]/manifests/sha256:18aace200d0ad2bf20e9beed69026b8a82a0db94324080ec66731fd2e270e67e"
> Request method: "HEAD"
> Request headers:
   "Accept": "application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json, application/vnd.oci.artifact.manifest.v1+json"
   "User-Agent": "oras/1.0.0" 
DEBU[0000] Response #0
< Response Status: "401 Unauthorized"
< Response headers:
   "X-Xss-Protection": "0"
   "Date": "Fri, 25 Aug 2023 12:59:53 GMT"
   "Content-Length": "102"
   "Content-Type": "application/json; charset=utf-8"
   "Docker-Distribution-Api-Version": "registry/2.0"
   "Www-Authenticate": "Bearer realm=\"https://us-central1-docker.pkg.dev/v2/token\",service=\"us-central1-docker.pkg.dev\",scope=\"repository:[...]:pull\""
   "X-Content-Type-Options": "nosniff"
   "X-Frame-Options": "SAMEORIGIN" 
DEBU[0000] Request #1
> Request URL: "https://us-central1-docker.pkg.dev/v2/token?scope=repository%3A[...]%3Apull&service=us-central1-docker.pkg.dev"
> Request method: "GET"
> Request headers:
   "User-Agent": "oras/1.0.0" 
DEBU[0000] Response #1
< Response Status: "403 Forbidden"
< Response headers:
   "X-Content-Type-Options": "nosniff"
   "X-Frame-Options": "SAMEORIGIN"
   "X-Xss-Protection": "0"
   "Date": "Fri, 25 Aug 2023 12:59:53 GMT"
   "Content-Length": "226"
   "Content-Type": "application/json; charset=utf-8" 
Error: HEAD "https://us-central1-docker.pkg.dev/v2/[...]/manifests/sha256:18aace200d0ad2bf20e9beed69026b8a82a0db94324080ec66731fd2e270e67e": GET "https://us-central1-docker.pkg.dev/v2/token?scope=repository%3A[...]%3Apull&service=us-central1-docker.pkg.dev": response status code 403: denied: Permission "artifactregistry.repositories.downloadArtifacts" denied on resource "projects/[...]/locations/us-central1/repositories/[...]" (or it may not exist)

The only difference on a successful debug log is that the second request has an additional header

"Authorization": "*****"

The debug logs don't show how it gets this header

@qweeah
Copy link
Contributor

qweeah commented Aug 28, 2023

Thank @jteichroeb-oanda The logs at least show snap build doesn't pick up the stored creds from credHelper.

@qweeah
Copy link
Contributor

qweeah commented Aug 28, 2023

@jteichroeb-oanda Just to confirm when you using downloaded oras binary and it succeeds, is it 1.0.0 or v1.0.1?

@jteichroeb-oanda
Copy link
Author

@qweeah both 1.0.0 and 1.0.1 work. I can't try 1.0.1 with snap since the lastest I see is 1.0.0.

@qweeah
Copy link
Contributor

qweeah commented Aug 28, 2023

Got it, taking a look. Thanks for the input. @jteichroeb-oanda

@FeynmanZhou
Copy link
Member

Upgrading the ORAS installer to v1.0.1 on Snap is still in WIP and tracked in #965 .

@shizhMSFT shizhMSFT added GCP Google Cloud Platform related issues logging labels Aug 29, 2023
@qweeah
Copy link
Contributor

qweeah commented Aug 29, 2023

@jteichroeb-oanda snap apps uses separated config file. You should add cred helper to the docker config in snap's virtual environment ~/snap/oras/current/.docker/config.json and it should work.

@jteichroeb-oanda
Copy link
Author

@qweeah that doesn't quite work either, it doesn't have a way to call the credential helper:

Error: failed to resolve latest: GET "https://us-central1-docker.pkg.dev/v2/[...]/manifests/latest": error getting credentials - err: docker-credential-gcloud resolves to executable in current directory (./docker-credential-gcloud), out: ``

@jteichroeb-oanda jteichroeb-oanda changed the title Using ORAS from snap can't authenticate with gcloud Using ORAS from snap can't authenticate with gcloud credential helper Aug 29, 2023
@qweeah
Copy link
Contributor

qweeah commented Aug 30, 2023

Looks like the credential helper needss to be accessible within the snap sandbox. I tried --classic installation and get the same error

Error: error storing credentials - err: docker-credential-pass resolves to executable in current directory (./docker-credential-pass), out: ...

@FeynmanZhou Maybe we should suggest user not to use snap release if they are using credstore or credhelpers, or even remove snap from the installation guide.

@FeynmanZhou
Copy link
Member

@qweeah If there is no workaround for the issue caused by the Snap sandbox environment, we can consider removing the Snap installation from the installation guide and dropping its maintenance for future releases.

@SamirPS Do you have any suggestions on this issue?

@shizhMSFT
Copy link
Contributor

Snap or Snappy is a package management system in Ubuntu with applications containerized and sandboxed.

Since a snap application runs in a sandbox environment, snap version of oras is not able to read the docker config and credential helpers directly and thus causing user experience problems.

Note

The home folder of the snap version of oras is ~/snap/oras/current.

@jteichroeb-oanda
Copy link
Author

One thing that confuses me, I have the gcloud command installed from snap as well, if it can access files outside of the sandbox environment, can't oras do the same thing?

@shizhMSFT
Copy link
Contributor

oras can access the files outside of the sandbox. For example, oras push <ref> file1 file2 where file1 and file2 can be at any place. However, oras cannot find docker-credential-gcloud in $PATH as $PATH has been modified by snap.

BTW, the error message docker-credential-gcloud resolves to executable in current directory (./docker-credential-gcloud) of oras v1.0.0 might be confusing. It is fixed in v1.0.1 as exec: "docker-credential-gcloud": executable file not found in $PATH.

@shizhMSFT
Copy link
Contributor

shizhMSFT commented Aug 30, 2023

Currently, oras is configured to strict confinement level.

confinement: strict

I'm not sure if setting confinement level to classic and install using --classic works or not. Noto to @qweeah, --classic flag does not work as it is not declared as classic.

Another thing we can try is the snap interfaces, mounting :home to oras:home.

@shizhMSFT
Copy link
Contributor

Oh. The :home is already connected.

$ snap connections oras
Interface  Plug          Slot      Notes
home       oras:home     :home     -
network    oras:network  :network  -

@SamirPS
Copy link
Contributor

SamirPS commented Sep 1, 2023

can it's been link to this ? https://forum.snapcraft.io/t/kubectl-wrong-gcloud-path-when-doing-any-operations/18848

i'm checking with other people to know the issue

@SamirPS
Copy link
Contributor

SamirPS commented Sep 3, 2023

Normally, with this interface, the snap will work: https://snapcraft.io/docs/personal-files-interface , I will update the snapcraft.yaml file and let's you test it.

@qweeah
Copy link
Contributor

qweeah commented Sep 4, 2023

@SamirPS I don't think using the personal file interface will be a good solution since user might use any config file via --config and specify any cred helper in the configuration. During build time, we cannot list out every possible path.

@qweeah
Copy link
Contributor

qweeah commented Sep 4, 2023

I'm not sure if setting confinement level to classic and install using --classic works or not. Noto to @qweeah, --classic flag does not work as it is not declared as classic.

Tried building a snapcraft version locally with confinement level set to classic and it worked: both config file and cred binaries can be successfully invoked. I think this is the most ideal solution we currently have.

@SamirPS
Copy link
Contributor

SamirPS commented Sep 4, 2023

thanks for the head up, i let you do the PR and publish it then :)

Copy link

github-actions bot commented Nov 4, 2023

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale Inactive issues or pull requests label Nov 4, 2023
@qweeah qweeah added this to the future milestone Nov 6, 2023
@qweeah qweeah removed the stale Inactive issues or pull requests label Nov 6, 2023
@qweeah
Copy link
Contributor

qweeah commented Nov 6, 2023

Putting it to future milestone to avoid being flagged as stale. To resolve issue here, we tried to convert oras a classic snap app and it's pending snapcraft's approval, see https://forum.snapcraft.io/t/request-for-classic-confinement-oras-and-oras-test/36826

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