Snapcraft login

I have created SNAPCRAFT_STORE_CREDENTIALS variable using content from ‘snapcraft export-login file’ command. But snapcraft login doesn’t work. Could someone help me with this? Output:

Cannot login with 'SNAPCRAFT_STORE_CREDENTIALS' set.                                                                                       
Recommended resolution: Unset 'SNAPCRAFT_STORE_CREDENTIALS' and try again.                                                                 
Full execution log: '/home/.../.local/state/snapcraft/log/snapcraft-20240624-152008.504598.log'


The SNAPCRAFT_STORE_CREDENTIALS variable is used instead of logging in, e.g:

# Make the credentials available to the shell
export SNAPCRAFT_STORE_CREDENTIALS="$(cat credential-file)"

# execute a command which requires you to be logged in,
# or a credential to be specified
snapcraft names

or this

SNAPCRAFT_STORE_CREDENTIALS="<credentials>" snapcraft names

Could you tell me what is inside this variable? I tried to use it using the export-login command, but it doesn’t work

It’s a long string of base64 encoded text that contains a macaroon.

I used export-login some months ago to generate the macaroon that @mr_cal described. I moved it into a container where I have a tool which uses the macaroon to gather metrics. Whilst I do not have access to the command I executed, I am reasonably certain it was this:

snapcraft export-login --acls package_metrics ~/acl

See here for a list of ACLs. (Aside: I think it would be helpful to include these in the CLI documentation, maybe I’ll investigate that in the near future).

If you did this, you could proceed to use the credential:

snapcraft names
snapcraft metrics --name daily_device_change --start 2024-01-01' --end '2024-06-25' --format json YourSnapName

The next action is to examine what you have executed and what your expectations were when doing so.

1 Like

If you export to SNAPCRAFT_STORE_CREDENTIALS long back, then you can run snapcraft whoami and see if the credentials are expired!! If the credentials are expired then set them again. It also shows what all permissions are allowed as well!!