Portus icon indicating copy to clipboard operation
Portus copied to clipboard

Docker msg="error authorizing context: insufficient scope"

Open dforste opened this issue 10 years ago • 6 comments

I have my docker instance setup behind a F5. I have portus setup there as well. I have docker login working properly but docker pull/push does not. Here is my registry config:

version: 0.1
log:
  fields:
    service: registry
  level: debug
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
  delete:
    enabled: true
http:
  addr: :5000
  debug:
    addr: :5001
  tls:
    certificate: /etc/docker/registry/io.domain.net.crt
    key:         /etc/docker/registry/io.domain.net.key
  secret: $registry_secret
auth:
  token:
    realm: https://io.domain.net:3000/v2/token
    service: io.domain.net
    issuer:  io.domain.net
    rootcertbundle: /etc/docker/registry/io.domain.net.crt

If I comment out the Auth section the registry will push/pull without issues.

Here is my portus config:

email:
  from: "[email protected]"
  name: "Portus"
  reply_to: "[email protected]"

  smtp:
    enabled: false
    address: "smtp.portus.domain.net"
    port: 587,
    user_name: "[email protected]"
    password: "password"
    domain: "portus.domain.net"

gravatar:
  enabled: true

ldap:
  enabled: true
  hostname: "192.168.5.167"
  port: 389
  method: "plain"
  base: "dc=domain,dc=net"
  filter: ""
  uid: "sAMAccountName"
  authentication:
    enabled: true
    bind_dn: '[email protected]'
    password: '$ad_password'
  guess_email:
    enabled: true
    attr: "targetAddress"

first_user_admin:
  enabled: true

signup:
  enabled: true

check_ssl_usage:
  enabled: false

jwt_expiration_time:
  value: "5.minutes"

machine_fqdn:
  value: "io.domain.net"

Here is my docker-compose:

portus:
  image: io.domain.net/portus:master
  restart: always
  volumes:
    - /app/docker/projects/docker_registry/portus/config.yml:/portus/config/config.yml
    - /app/docker/projects/docker_registry/portus/io.domain.net.key:/portus/config/io.domain.net.key
  environment:
    - PORTUS_PRODUCTION_HOST=io.domain.net
    - PORTUS_PRODUCTION_USERNAME=portus
    - PORTUS_PRODUCTION_PASSWORD=$portus_password
    - PORTUS_PRODUCTION_DATABASE=portus
    - PORTUS_SECRET_KEY_BASE=$portus_secret
    - PORTUS_MACHINE_FQDN=io.domain.net
    - PORTUS_KEY_PATH=/portus/config/io.domain.net.key
    - PORTUS_PASSWORD=$portus_password
  ports:
    - "3000:3000"
  command:
    - /usr/local/bundle/bin/puma
    - -C
    - /portus/config/puma.rb
    - -e
    - production
    - --debug

registry:
  image: io.domain.net/registry:2.3
  restart: always
  volumes:
    - /nfs/dockerreg:/var/lib/registry
    - /app/docker/projects/docker_registry/registry/config.yml:/etc/docker/registry/config.yml
    - /app/docker/projects/docker_registry/registry/io.domain.net.key:/etc/docker/registry/io.domain.net.key
    - /app/docker/projects/docker_registry/registry/io.domain.net.crt:/etc/docker/registry/io.domain.net.crt
  ports:
    - "5000:5000"
    - "5001:5001"

I see the following from portus when doing "docker -D login -u dforster io.domain.net:5000":

Started GET "/v2/token?account=dforster&service=io.domain.net" for $f5_IP at 2016-03-03 21:11:32 +0000
Processing by Api::V2::TokensController#show as JSON
  Parameters: {"account"=>"dforster", "service"=>"io.domain.net"}
Completed 200 OK in 1168ms (Views: 0.2ms | ActiveRecord: 46.5ms)

Docker responds Login Succeeded. The Registry logs this:

time="2016-03-03T21:18:00.028224221Z" level=debug msg="authorizing request" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=e8d57cf4-53a1-4e4d-8e21-8a1b66cdc7b6 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
time="2016-03-03T21:18:00.028336948Z" level=warning msg="error authorizing context: authorization token required" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=e8d57cf4-53a1-4e4d-8e21-8a1b66cdc7b6 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
$f5_IP - - [03/Mar/2016:21:18:00 +0000] "GET /v2/ HTTP/1.1" 401 87 "" "docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64"
time="2016-03-03T21:18:00.275104263Z" level=debug msg="authorizing request" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=42b094bd-ab97-4b57-9b43-931530ce1826 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
time="2016-03-03T21:18:00.275540559Z" level=info msg="response completed" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=42b094bd-ab97-4b57-9b43-931530ce1826 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" http.response.contenttype="application/json; charset=utf-8" http.response.duration=2.1682215ms http.response.status=200 http.response.written=2 instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
$f5_IP - - [03/Mar/2016:21:18:00 +0000] "GET /v2/ HTTP/1.1" 200 2 "" "docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64"

When I try to do a pull portus looks like it is authorizing as it should.

Started GET "/v2/token?account=dforster&scope=repository%3Aadmin%2Fregistry%3Apush%2Cpull&service=io.domain.net" for $f5_IP at 2016-03-03 21:16:07 +0000
Processing by Api::V2::TokensController#show as JSON
  Parameters: {"account"=>"dforster", "scope"=>"repository:admin/registry:push,pull", "service"=>"io.domain.net"}
Completed 200 OK in 121ms (Views: 0.2ms | ActiveRecord: 43.0ms)

The Registry responds differently:

time="2016-03-03T21:20:00.242405154Z" level=debug msg="authorizing request" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=40a4723e-dab9-478a-87b1-13563661e516 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
time="2016-03-03T21:20:00.24168016848Z" level=warning msg="error authorizing context: authorization token required" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=40a4723e-dab9-478a-87b1-13563661e516 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
$f5_IP - - [03/Mar/2016:21:20:00 +0000] "GET /v2/ HTTP/1.1" 401 87 "" "docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64"
time="2016-03-03T21:20:00.489477014Z" level=debug msg="authorizing request" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=60a7caaf-0e5a-4282-88fa-e4bcdf884c22 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/admin/registry/manifests/2.3" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry vars.name="admin/registry" vars.reference=2.3 version=v2.3.0
time="2016-03-03T21:20:00.489952788Z" level=warning msg="error authorizing context: insufficient scope" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=60a7caaf-0e5a-4282-88fa-e4bcdf884c22 http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/admin/registry/manifests/2.3" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry vars.name="admin/registry" vars.reference=2.3 version=v2.3.0
$f5_IP - - [03/Mar/2016:21:20:00 +0000] "GET /v2/admin/registry/manifests/2.3 HTTP/1.1" 401 146 "" "docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64"
time="2016-03-03T21:20:00.560864774Z" level=debug msg="authorizing request" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=e8c00454-b77b-4604-8824-7ec1c92f3bec http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
time="2016-03-03T21:20:00.560934353Z" level=warning msg="error authorizing context: authorization token required" go.version=go1.5.3 http.request.host="io.domain.net:5000" http.request.id=e8c00454-b77b-4604-8824-7ec1c92f3bec http.request.method=GET http.request.remoteaddr=192.168.184.115 http.request.uri="/v2/" http.request.useragent="docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64" instance.id=8ee32786-fe6a-4d26-ab50-f6d716c1311c service=registry version=v2.3.0
$f5_IP - - [03/Mar/2016:21:20:00 +0000] "GET /v2/ HTTP/1.1" 401 87 "" "docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64"
$f5_IP - - [03/Mar/2016:21:20:00 +0000] "GET /v1/repositories/admin/registry/images HTTP/1.1" 404 19 "" "docker/1.8.2 go/go1.4.2 kernel/3.10.0-327.el7.x86_64 os/linux arch/amd64"

I am building a docker container to run from the master branch. I think I had to use 2.0.3 to seed the database though.

Why won't docker authorize the requests?

dforste avatar Mar 03 '16 21:03 dforste

As it turns out I needed the Service in the Registry auth section to be the same as the hostname in the portus configuration with port as well.

dforste avatar Mar 04 '16 20:03 dforste

@dforste what were your final settings? Which hostname did you change to match?

emcniece avatar Oct 19 '16 06:10 emcniece

@emcniece What I have now and what is in the issue I think it was from the auth section for the registry.

Here is the example from my auth section in the registry config:

auth:
  token:
    realm: https://portus.domain.net/v2/token
    service: dockerhub.domain.net
    issuer:  io.domain.net
    rootcertbundle: /etc/docker/registry/io.domain.net.crt
notifications:
  endpoints:
    - name: portus
      url: https://portus.domain.net/v2/webhooks/events
      timeout: 500ms
      threshold: 5
      backoff: 1s
  secret: fffffffffffffffffffffffffffff

We still run the old certs with io.domain.net but that doesn't seem to matter that much.

dforste avatar Oct 19 '16 21:10 dforste

I had this same issue. To clarify: REGISTRY_AUTH_TOKEN_SERVICE must be set to the same hostname of the registry as configured in Portus database.

(Also related #631)

macropin avatar Oct 21 '16 02:10 macropin

I had the same problem too, and already follow macropin's comment to sloved this problem. But i dont know where is Portus database's config about registry hostname ,so I just change in webUI(admin->Registries ->edit hostname),and edit the hostname the same with REGISTRY_AUTH_TOKEN_SERVICE.(i added ":5000" before,so it's no the same ) Thanks agains,and hope this may be helpful for others.

x1aoj1ang avatar Mar 15 '18 03:03 x1aoj1ang

Same problem: I set "External Registry Name" wrong.

PS When I come here the next time take a walk.

SuperSandro2000 avatar Feb 08 '20 19:02 SuperSandro2000