Gitea Docker Registry - Unauthorized on first login? - docker-registry

I have a Jenkins pipeline where a Docker (Podman) image is built und pushed to a private Gitea docker registry. This basically works. But I have the problem, that the first build after several hours, that means on the next day, crashes because pushing to the Gitea registry leads to:
Error: writing blob: uploading layer to https://192.168.0.5:4000/v2/myorg/myproject/blobs/uploads/ptuh7yizsrqvx5wlg9uctlzdv?digest=sha256%3A7ca0dabc572c112e5141bac7e5f29a0c1b1f727ce939ac1e7da342d3adf324a: received unexpected HTTP status: 500 Internal Server Error
When I click on the link, it shows me:
errors
0
code "UNAUTHORIZED"
message ""
Since I trigger the login from a remote host via Jenkins pipeline, I do that with a script, but I'm pretty sure that this does not matter. The content at the script is:
#!/bin/bash
podman login -u builderuser -p builderpassword 192.168.0.5:4000
I see in the logs that Login Succeeded!, but after the next step, I get the error from above after it tries to copy the blob to the registry.
I also tried to add a "logout" before login in the script via
podman logout 192.168.0.5:4000
But this does not help either.
When I trigger the same build again, the process works without problems. Maybe some caching problem anywhere? The problem appears at the first build on the next day, so I guess there is some session timeout anywhere after several hours. Any ideas?
[UPDATE]
I think this is a bug in Gitea. In log I see this:
Nov 11 08:50:40 server gitea[34985]: 2022/11/11 08:50:40 ...es/container/blob.go:66:func1() [E] [636dfed0-7] Error inserting package: pq: duplicate key value violates unique constraint »UQE_package_version_s«
And in code of Gitea in auths.go, I see a comment leading me to the assumption that they are aware of this problem:
// FIXME: if the name conflicts, it will result in 500: Error 1062: Duplicate entry 'aa' for key 'login_source.UQE_login_source_name'
What I still don't understand is, why this happens only once, at the beginning of the day, and not always.

Did you check the logs on the registry?
If you get something like
<path>/registry/docker: permission denied
it means the error happens if your user does not have the permission to write.
If on the permission side you're ok, than the error shown is quite random and has the same root cause as gitlab-org/gitlab#215715
The error has been fixed for gitlab. You'd need to check on Jenkins if they have some open issues similar to this.

Related

Why jib dockerBuild plugin fails to connect

I was trying to build the docker image for a project I'm working onto.
It's based on jhipster, after configuring the project it tells me to run the following maven command:
./mvnw -ntp -Pprod verify jib:dockerBuild
Unfortunately it doesn't seem to work, it returns me this errors:
[WARNING] The credential helper (docker-credential-pass) has nothing for server URL: registry.hub.docker.com
...
[WARNING] The credential helper (docker-credential-pass) has nothing for server URL: index.docker.io
[WARNING]
And finally fails with:
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.4.0:dockerBuild (default-cli) on project booking: (null exception message): NullPointerException -> [Help 1]
Recently I worked on a google cloud project, and I edited the ~/.docker/config.json configuration file. I had to remove google's configuration entries to sort out another problem. Could that be the origin of the problem I'm facing now?
I've tried to do docker logout and docker login without success.
Some considerations
I don't know if editing manually the configuration caused the error, in fact I'm pretty sure to have deleted only google-related entries, but nothing referring to docker.* or similar.
To solve this issue, avoid to edit manually the docker configuration file. In fact I think that it should be avoided whenever possible, to avoid configuration problems of any sort.
Instead, just follow what the error message is trying to tell you: docker is not able to access those urls. Excluding network problems (which you can troubleshoot with ping registry-1.docker.io for example), it should be an authentication problem.
How to fix
I've found out that running those commands fixed it:
docker login registry.hub.docker.com
docker login registry-1.docker.io
I don't know if registry-1.docker.io is just a mirror of the other first server, which the plugin tries to access after the first unsuccessful connection. You can try to loging to registry.hub.docker.com and re-launch the command to see if it sufficient. In case it's not, login to the second one and then it will work.
I ran jib via Gradle:
./gradlew jibDockerBuild
and got a similar error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jibDockerBuild'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Build to Docker daemon failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/openjdk' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help
What ended up solving this error for me, bizarrely enough, was to log out of Docker Desktop.
I later also tried funder7's solution while logged in to Docker Desktop, and that also worked.

Artifactory in docker get 404 on file with a hash symbol (#) when trying to download via the UI

I had this happen on my regular instance of Artifactory oss so I made a clean install with minimum configuration change to check everything.
On a clean install of Artifactory :
Version : Artifactory oss 7.3.2 (docker version)
The command used to create the docker : docker run --privileged=true --name=artifactory -i -d -v /media/sdb1/Artifactory:/media/sdb1/Artifactory:z -p 8082:8082 docker.bintray.io/jfrog/artifactory-oss:latest
Everything works fine for regular file
I can upload a file with a hash symbol in it ex: test#1_hashtag. txt
When I try to download it with the UI I end up here : http://my.dns.com:8082/ui/api/v1/download?repoKey=generic-local&path=test%231_hashtag.txt
There is this error displayed :
errors
0
status 404
message "File not found."
I can download the file with curl
I still get the error even when I connect via IP.
I am looking to fix this since not being able to use the hash symbol (#) would need us to rename a lot of files. I don't know if it's due to redirect or something. But this installation is 100% what come out of the box.
Edit : It's not a problem of understanding how the hash symbol in the link is working, I know how it works. it's a problem of special character not being handled correctly by the app or by the redirect.
It looks like you are running into a regression. This seems to have been working 6.16.2 and broken in 7.3.2 (the versions I tested, not necessarily where the regression happened, which is likely in 7.0). There is a bug open for it: https://www.jfrog.com/jira/browse/RTFACT-21460. Please vote for and follow it up for updates.

Neo4j: Can't log in: Neo.ClientError.Security.Unauthorized: The client is unauthorized due to authentication failure

When I do :server connect with neo4j and neo4j I get Neo.ClientError.Security.Unauthorized: The client is unauthorized due to authentication failure..
I tried uncommenting the line dbms.security.auth_enabled=false in /etc/neo4j/neo4j.conf and restarting, but it still asks me to log in and still denies the login.
I can get in with /usr/bin/cypher-shell -u neo4j -p neo4j
I tried /usr/bin/neo4j-admin set-initial-password secret but it says command failed: The specified user 'neo4j' already exists.
I tried sudo rm /var/lib/neo4j/data/dbms/auth and restarting, but it gives the same result.
ubuntu 16.04
Installed with sudo apt-get install neo4j=1:3.5.0
I had the same problem. I tried to set the initial password and it said The specified user 'neo4j' already exists. I had thought I had set the initial password earlier via the command line, but it didn't take because there were special characters in the password string.
What ended up working for me was opening up the Neo4j Browser and it prompted me for a password. I entered 'neo4j' and then it gave me the option to set a new password through the browser. Once I did that, it worked.
If you need to turn off auth_enabled to test something, make sure to remember to restart the server. sudo neo4j restart It can also take a few minutes to restart, so make sure it's fully up and running first. (And then, of course, don't forget to turn auth_enabled back on again.)
It also took me a few tries to get the configuration correct in the conf file at /etc/neo4j/neo4j.conf
I set dbms.connectors.default_listen_address=0.0.0.0
And dbms.connectors.default_advertised_address=your.webdomain.com
Also, this guide helped me with setting up a certificate for the neo4j browser endpoint. https://medium.com/neo4j/getting-certificates-for-neo4j-with-letsencrypt-a8d05c415bbd
I faced the issue with the initial setup. Kept getting the same unauthorised message. The issue with me was I was trying to access it in firefox. Tried in Chrome and it worked and prompted me to change my password. Found one issue stating this:
< connecting to Neo4j browser through Firefox >
I disabled/uncomment authenitication in /etc/neo4j/neo4j.conf
To disable authentication, uncomment this line
dbms.security.auth_enabled=false
it worked for me.
Make sure to comment it back when you are done for security purposes

CircleCI - Git could not resolve host when cloning repository

When running npm install within circleci we fetch some node packages from our github repositories through package.json. This operation is happening when building a docker image from a Dockerfile.
This has been working great until last week when without changes in our side, we started to get errors while cloning these packages. To perform this operation, we were using Basic Authentication in the URL providing user credentials in it. For ie:
https://<username>:<password>#github.com/elektron-technogoly/<repository>.git
Now, we get the following errors:
npm ERR! Command failed: git clone ...
npm ERR! fatal: unable to access 'https://<username>:<password>#github.com/elektron-technogoly/<repository>.git':
Could not resolve host: <username>
From the error message it seems like it thinks the username is the host and thus, fails. I checked that password is still valid and it did not expire.
Has recently - around last week - something changed that could cause this error? Has Basic Authentication been disabled?
UPDATE: Playing a bit seems like when you change the base docker image (say from node:4-slim to node:4), the first time it works, subsequent times don't. Unfortunately, logs are not giving me any lead, both look exactly the same but the error appears from the first onwards.

Kubernetes: Unable to create repository

I'm following Kubernete's getting started guide. Everything went smoothly until I ran
$ gcloud docker push gcr.io/<PROJECT ID>/hello-node:v1
(Where is, well, my project id). For some reason, Kubernetes is not able to push to the registry. This is what I get:
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
Warning: '--email' is deprecated, it will be removed soon. See usage.
Login Succeeded
The push refers to a repository [gcr.io/kubernetes-poc-1320/hello-node]
18465c0e312f: Preparing
5f70bf18a086: Preparing
9f7afc4ce40e: Preparing
828b3885b7b1: Preparing
5dce5ebb917f: Preparing
8befcf623ce4: Waiting
3d5a262d6929: Waiting
6eb35183d3b8: Waiting
denied: Unable to create the repository, please check that you have access to do so.
Any ideas on what I might be doing wrong? Note that I have run. $ gcloud init, so I've logged in.
Thanks in advance!
This solved it in my case:
Short version:
Press Enable billing in the Container Engine screen in the https://console.cloud.google.com.
Long version:
In my case I got the error because of an issue with setting billing in the google cloud platform console.
Although I entered all my credit card information and the screen of my Container Engine Screen in the google cloud platform console said Container Engine is getting ready. This may take a minute or more., it didn't work before I pressed Enable billing on the same screen. Then the gcloud docker push command finally worked.
Oddly enough after later returning to the Container Engine screen, it shows me Container Engine is getting ready. This may take a minute or more. and the button Enable billing again.. must be a bug in the console.
None of the above solutions worked for me and I finally found out a solution. I'm using Windows 10 and looked at my C:/Users//.docker/config.json file and it looked like this.
{
"auths": {
"https://appengine.gcr.io": {},
"https://asia.gcr.io": {},
"https://b.gcr.io": {},
"https://bucket.gcr.io": {},
"https://eu.gcr.io": {},
"https://gcr.io": {},
"https://gcr.kubernetes.io": {},
"https://us.gcr.io": {}
},
"credsStore": "wincred"
}
Removing the "credsStore": "wincred" line fixed the problem!
If you're using a GCE instance, you need to make sure it has the right Cloud API access scope.
Since you can't edit the scopes on running instances, you can create a new instance using your current disk.
To do that, do the following
Go to your instance page and click Edit
Uncheck Delete boot disk when instance is deleted and click save
Create a new instance using your previous disk and with write permissions on Storage.
I was getting this same error because I was accidentally using the project name rather than the auto-generated id. The PROJECT_ID can be found via:
$ gcloud info
as well as in the Google Cloud dashboard: https://console.cloud.google.com/home/dashboard
Silly, I realize, but I can imagine others making the same mistake :)
Ensure you are authenticated with Google Cloud.
$ gcloud auth application-default login
Double-check gcloud is pointing to your current project.
$ gcloud config set project PROJECT_ID
If you still have trouble, run gcloud info and take a look at the Last Log File. Note: gcloud auth login no longer writes application default credentials.
In https://stackoverflow.com/a/39996807/598513 I answered switching user/account
gcloud auth list
gcloud config set account example#gmail.com
Edit: This worked for me months ago. New versions of Kubernetes might not have this problem, or this solution might not solve it :)
Ok, after struggling for hours with this, I finally managed to push it to th grc.io registry by changing my tag from a image:version notation to image/version, like this:
gcloud docker push gcr.io/<PROJECT ID>/hello-node/v1
after reading another guide from Kubernetes' documentation: https://cloud.google.com/container-registry/docs/pushing#pushing_to_the_registry
Hope this helps!
For me, having the same error, I found I missed the "gcloud" in the beginning. That was because previous 2 commands started with docker and I just glanced over the changes after docker.
~/gs-spring-boot/complete$ docker -- push gcr.io/kubernetes-codelab-1xxxxx/hello-java:v1
correct:
~/gs-spring-boot/complete$ gcloud docker -- push gcr.io/kubernetes-codelab-1xxxxx/hello-java:v1
run gcloud init and see whether you have logged in to the correct account. I once had this error because of i was trying to push image from different google account
When using docker-credential-helpers to store docker credentials in the OSX Keychain, gcloud docker -- push $registry/$project_id/<image>:<tag> fails as well.
Solution for me was to revert ~/.docker/config.json to not store credentials securely with the keychain
See also: https://github.com/GoogleCloudPlatform/gcloud-common/issues/198
What do you use as a project id? It shouldn't be "my-kubernetes-codelab", it should be "my-kubernetes-codelab-234231" or whatever your numbered version is. This was my problem.

Resources