1

I am trying to setup Drone CI 0.6 with Github. However I keep getting oauth errors. Perhaps someone can point out what I am doing wrong. I have tried both with & without DRONE_HOST, but it always says there is a mismatch.

Error:

cannot authenticate user. redirect_uri_mismatch The redirect_uri MUST match the registered callback URL for this application. https://developer.github.com/v3/oauth/#redirect-uri-mismatch

docker-compose.yml :

version: '2'

services:
  drone-server:
    image: drone/drone:0.6
    ports:
      - 8822:8000
    volumes:
      - /var/lib/drone:/var/lib/drone/
    restart: always
    environment:
      - DRONE_OPEN=true
      - DRONE_HOST=http://ci.rallabs.com
      - DRONE_GITHUB=true
      - DRONE_GITHUB_CLIENT=myGithubClient
      - DRONE_GITHUB_SECRET=myGithubSecret
      - DRONE_SECRET=mySecret
  drone-agent:
    image: drone/drone:0.6
    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=ws://drone-server:8000/ws/broker
      - DRONE_SECRET=mySecret

Github app details:

Github settings

Brenwell
  • 767
  • 10
  • 24

1 Answers1

5

A common reason for redirct_url mismatch is because drone is running behind a reverse proxy (e.g. nginx) and cannot figure out its own address to properly construct the redirect url. The solution to this is to setup the X-Forwarded-For and X-Forwraded-Proto parameters allowing Drone to determine its own address.

For nginx, as of version 0.6, this is the recommended nginx configuration from the docs [1]

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    server_name drone.example.com;

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;

        proxy_pass http://127.0.0.1:8000;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_buffering off;

        chunked_transfer_encoding off;
    }

    location ~* /ws {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
    }
}

[1] http://docs.drone.io/setup-with-nginx/

Brad Rydzewski
  • 2,523
  • 14
  • 18