Error pushing image via docker registry v2 api - docker

I was start pushing an image to private docker registry after getting authorization token. However the request gets failed due to unauthorized access. There is not enough documentation on what are the body parameters that this particular endpoint expects.Could anyone tell me what am i doing wrong?
curl -k -v -L -H "Authorization: Bearer ${token}" -X POST "https://***/v2/helloworld/image1/blobs/uploads/"
> Host: ****
> User-Agent: curl/7.43.0
> Accept: */*
> Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlZDWUo6UDdWVjpTS1Q0OlVGNUM6VTVYMjpUR01YOk9QWUs6TTY2Rjo3UkZEOkJTSTI6VVJFSjpFUDMyIn0.eyJpc3MiOiJBdXRoIFNlcnZpY2UiLCJzdWIiOiIiLCJhdWQiOiJEb2NrZXIgcmVnaXN0cnkiLCJleHAiOjE0ODc2NTM2NDgsIm5iZiI6MTQ4NzY1MjczOCwiaWF0IjoxNDg3NjUyNzQ4LCJqdGkiOiI3ODI1ODcwNDY1NDc2Mjg4NzA3IiwiYWNjZXNzIjpbeyJ0eXBlIjoicmVwb3NpdG9yeSIsIm5hbWUiOiJuZXV0cm9uL3JlYWN0aXZlLXByaWNpbmctb2ZmZXJzLWZ1bGZpbGxtZW50IiwiYWN0aW9ucyI6W119XX0.2zQ8GcbLlg26O-dgBQYXMEnOlsDfxonkjy5VhGmq325eDv69C5C28WHiFf6fTLBUNw6YnBv6Ty20ZakuzRPzUHq-C2IVyqMjSymYs_VaaKtRMSCLo-DtVgKL9sSDtWSRd6N2aOk8g5AeQvcs3FaYnE5QQCzho6t79zXd6vUYJV4
>
< HTTP/1.1 401 Unauthorized
< Content-Type: application/json; charset=utf-8
< Date: Tue, 21 Feb 2017 04:57:05 GMT
< Docker-Distribution-Api-Version: registry/2.0
< Server: Apache
< Vary: Accept-Encoding,User-Agent
< Www-Authenticate: Bearer realm="https://****/auth",service="Docker registry",scope="repository:****/****:pull,push",error="insufficient_scope"
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Content-Length: 266
< Connection: keep-alive
<
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Name":"***/***","Action":"pull"},{"Type":"repository","Name":"***/***","Action":"push"}]}]}
Note: I have admin access to the docker repository
Thanks,
Mahesh

Related

How to list repositories/catalog in IBM Container Registery?

I am using IBM Container Registry and trying to list the repositories/catalog using the below command.
curl -i https://us.icr.io/v2/_catalog
HTTP/2 401
content-type: application/json; charset=utf-8
www-authenticate: Bearer realm="https://us.icr.io/oauth/token",service="registry",scope="registry:catalog:*",error="invalid_token"
The www-authenticate field state that the scope of the token should be registry:catalog:*.
When I tried to create a token with this scope, the generated token provides an empty access list.
Running the command with above generated access token gives the below error:
curl -i -H "Authorization: Bearer $token" https://us.icr.io/v2/_catalog
HTTP/2 403
content-type: application/json; charset=utf-8
www-authenticate: Bearer realm="https://us.icr.io/oauth/token",service="registry",scope="registry:catalog:*",error="insufficient_scope"
date: Mon, 23 May 2022 16:53:38 GMT
content-length: 134
cache-control: no-cache, no-store, must-revalidate
content-security-policy: default-src 'self'; frame-ancestors 'none'; form-action 'none';
docker-distribution-api-version: registry/2.0
expires: 0
pragma: no-cache
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-frame-options: DENY
x-registry-supports-signatures: 1
x-xss-protection: 1; mode=block
server: IBM Cloud Container Registry
{"errors":[{"code":"DENIED","message":"insufficient scope","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}
Does IBM Container Registry support _catalog docker v2 api?
Are there any other way to list the repositories?
Note: I have tried https://cloud.ibm.com/apidocs/container-registry#list-images, it lists all the images but not the repositories like _catalog docker v2 api.
According to the IBM Cloud Container Registry documentation and the experience you made, that API is not supported.
IBM Cloud Container Registry supports Docker Engine v17.07, or later.
Docker itself defines the Engine API, Hub API and the Registry API. The latter has the function you asked for.

HTTP Request with content-length > 0 but body is empty in docker container

I am trying to run curl commands in a groovy script and containerize it using docker. The script runs a bunch of curl commands. Using the following code to execute the commands.
def process = commandArray.execute()
def out = new StringBuffer()
process.consumeProcessOutputStream(out)
if (process.isAlive()) process.waitForOrKill(240000)
Things work fine when I run locally. But When I execute the groovy script in container the response body comes as empty but the Content-Length will be more than 0.
My headers are as below(Have Replaced few content with dummy data, ex: xyz.com)
* TCP_NODELAY set
* Connected to xyz.com (10.20.30.400) port 80 (#0)
> GET /abc/xyz/type HTTP/1.1
> Host: xyz.com
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< cache-control: no-cache, private
< etag: "000000000000000000000000000000"
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< strict-transport-security: max-age=31536000 ; includeSubDomains
< x-frame-options: DENY
< content-type: application/json
< content-length: 72950
< date: Tue, 22 Jun 2021 06:17:09 GMT
< x-envoy-upstream-service-time: 57
< server: envoy
<
{ [15940 bytes data]
* Connection #0 to host xyz.com left intact
Although the content-length: 72950 when I print the out object, it is empty []
What might be going on here? This issue is specific to running in container
The curl command looks as below
curl -s -v -L -k -X 'GET' --cert '/tmp/groovy-generated-10305010891926264191-tmpdir/client-cert.pem' --proxy 'https://proxy.com:30000' --noproxy 'localhost,127.0.0.1' 'https://example.com/abc/xyz/type'

Unable to post telemetry data using HTTP from command line

Unable to post telemetry data using HTTP from command line, I can not get any message in my thingsboard Platform
C:\Users\Administrator>curl -v -X POST -d "{\"temperature\": 25}" http://localhost:8080/api/v1/mdULJGYox2jQmDmFbZID/telemetry --header "Content-Type:application/json"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /api/v1/mdULJGYox2jQmDmFbZID/telemetry HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type:application/json
> Content-Length: 19
>
* upload completely sent off: 19 out of 19 bytes
< HTTP/1.1 200
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< Content-Length: 0
< Date: Wed, 15 Jul 2020 07:36:48 GMT
<
* Connection #0 to host localhost left intact
i'm new to thingsboard. I also encountered the same issue right now. But it works when i use postman to send the same http request to a locally installed se. So maybe it gets stuck in the curl command.

What params is devise_auth_token expecting?

Devise_auth_token newbie here. I have a rails 5 api only app. I'm trying to make requests to my api using curl and I have managed to do so successfully except for when I want to sign in a user.
curl -XPOST -H 'Content-Type: application/json' -d '{ "session": { "email":"example2#gmail.com", "password": "password"}}' localhost:3000/auth/sign_in
Not sure what I am doing wrong. As I said, for some reason there is no problem when creating a user. When trying to sign in I get this error
{"errors":["Invalid login credentials. Please try again."]}
Any help is greatly appreciated, thank you.
curl -v -XPOST -H 'Content-Type: application/json' -d '{ "email":"admin#example.com", "password": "password"}' localhost:3000/auth/sign_in
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /auth/sign_in HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:3000
> Accept: */*
> Content-Type: application/json
> Content-Length: 55
>
* upload completely sent off: 55 out of 55 bytes
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Type: application/json; charset=utf-8
< access-token: Bm3FaRpSAjT-EtTrj8Ucww
< token-type: Bearer
< client: 6XCiYTxcEITVRZItRKFa8w
< expiry: 1480750998
< uid: admin#example.com
< ETag: W/"be9091473a08ccf2672b9685eb25caa2"
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: 4996fb00-a45c-41e4-b30b-c86bc10b24d5
< X-Runtime: 0.737506
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
{"data":{"id":1,"email":"admin#example.com","provider":"email","uid":"admin#example.com","name":null,"nickname":null,"image":null}}
Use -v for curl - it will give you many clues.
Comment was right - do not place login / password inside session.
Snip from TL;DR that you should read thoroughly:
The authentication headers consists of the following params: access-token, client, expire, uid
The authentication headers required for each request will be available in the response from the previous request.

Response Value Does Not Return After Successfully Login With CURL

I had problem which is I cannot get response value even though sign in into rails app using curl post going through. This is my CURL command:
curl -i -H 'Content-Type: application/json' -X POST http://localhost:3000/users/sign_in -d '{"user": {"email": "admin#admin.com", "password": "abc12345"}}'
and this is http status I got:
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Etag: W/"fa9a29286a105efca890fba3ae3fc084"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: a4ecab97-f7fe-4354-834a-f2ac07faa871
X-Runtime: 0.332680
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
Date: Wed, 29 Jul 2015 16:24:05 GMT
Content-Length: 8205
Connection: Keep-Alive
Set-Cookie: request_method=POST; path=/
Set-Cookie: _stuckplaces_session=WmNOeUxyMW9Mc1M3aUx0R3J5U29ZUU85bzJoeEF5T0dCb0F3eG9GdVdsV2hMUGtRSFhIVnRZWHI3bXNKbnlZUTF2c0NJNVQxeEdMYldNSEl5WEVGZlU0dHJWYUNFVWx2bDVaRXJCdWcvd29ZWlRwMHJ6SnhjeHRHeDRmNFByVjI0a1dhbTZZWkxnb0t6Ky9LYnZtTFVZOFE1Tk8vQ1B4T0ZkUG00UGpyU0dpK2NZcUVhLzY1MzhMMnhGZTZ2UkFaOC9VTzNKZXFGQ3B1dWFpcmV3M2JZU1FUdUNnWjhqOUhvbld0M3B2eHdrSVRNT1BNV1ZpSjdQQTVoYkFNMjJYdC0tZktIaFBDc1VZVVltM29mVDU2eDlLUT09--cbf739d14b947b3631d82f2c6d1283a95bede14b; path=/; HttpOnly
and what I expected for response value is something like this
HTTP/1.1 200 OK
{"response":{"user_id":2,"token":"6c54adfb9fd41e33738f3b3707e9726b"}}
view raw
I hope something could help me with this problem, thank you in advance.
You need to modify your sessions controller to respond with JSON containing the required response. You can use this link for reference.

Resources