Skip to content

Reverse proxy authentication to Woodpecker CI and Gitea#837

Closed
pboguslawski wants to merge 19 commits into
woodpecker-ci:masterfrom
ibpl:master-IB#1107569
Closed

Reverse proxy authentication to Woodpecker CI and Gitea#837
pboguslawski wants to merge 19 commits into
woodpecker-ci:masterfrom
ibpl:master-IB#1107569

Conversation

@pboguslawski
Copy link
Copy Markdown
Contributor

This mod adds option to authenticate user using HTTP header set by
reverse proxy. It forwards specified HTTP header with authenticated
username in requests to Gitea.

Requirements:

To enable set the following variables in woodpecker server
environment (woodpecker running behind reverse proxy):

  • internal woodpecker server URL, i.e.:

    WOODPECKER_HOST_INTERNAL=http://192.168.1.100:8000/

  • enable reverse proxy auth in woodpecker and forwarding auth
    header to gitea:

    WOODPECKER_GITEA_REV_PROXY_AUTH=true

  • set name of header with authenticated username (set by
    reverse proxy), i.e.:

    WOODPECKER_GITEA_REV_PROXY_AUTH_HEADER=X-Forward-Username

Related: go-gitea/gitea#15119
Author-Change-Id: IB#1107569

This mod adds option to authenticate user using HTTP header set by
reverse proxy. It forwards specified HTTP header with authenticated
username in requests to Gitea.

Requirements:

* Gitea must be configured for reverse proxy authentication and
  must accept HTTP header auth in API calls
  (go-gitea/gitea#15119).

To enable set the following variables in woodpecker server
environment (woodpecker running behind reverse proxy):

* internal woodpecker server URL, i.e.:

  WOODPECKER_HOST_INTERNAL=http://192.168.1.100:8000

* enable reverse proxy auth in woodpecker and forwarding auth
  header to gitea:

  WOODPECKER_GITEA_REV_PROXY_AUTH=true

* set name of header with authenticated username (set by
  reverse proxy), i.e.:

  WOODPECKER_GITEA_REV_PROXY_AUTH_HEADER=X-Forward-Username

Related: go-gitea/gitea#15119
Author-Change-Id: IB#1107569
@6543 6543 added enhancement improve existing features forge/gitea gitea forge related labels Mar 9, 2022
Copy link
Copy Markdown
Contributor

@qwerty287 qwerty287 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Docs are missing, please add them.
  2. Please remove the chsnged copyright headers, we do this nowhere else.

Comment thread cmd/server/flags.go
Comment thread server/remote/gitea/gitea.go Outdated
Copy link
Copy Markdown
Contributor

@qwerty287 qwerty287 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand this PR, but why do you disable OAuth2 for the rev proxy auth? I'm not an expert with reverse proxies, but shouldn't it be possible to use OAuth2 with them?

@pboguslawski
Copy link
Copy Markdown
Contributor Author

pboguslawski commented Jul 22, 2022

I don't fully understand this PR, but why do you disable OAuth2 for the rev proxy auth? I'm not an expert with reverse proxies, but shouldn't it be possible to use OAuth2 with them?

If you use proxy for authentication, proxy is responsible for this and backend apps like gitea or woodpecker should trust it (user login passed in specified header). Because woodpecker must authenticate to gitea using HTTP call, it must also be able to forward header with user login to authenticate user in gitea. OAuth2 is different/separate auth logic and I don't see any point in trying to use it along with proxy auth using HTTP headers.

@pboguslawski
Copy link
Copy Markdown
Contributor Author

  1. Docs are missing, please add them.

    1. Please remove the chsnged copyright headers, we do this nowhere else.

Fixed.

@pboguslawski pboguslawski requested a review from qwerty287 July 22, 2022 14:24
@6543
Copy link
Copy Markdown
Member

6543 commented Sep 28, 2022

well sorry that we dont come allong to review it ...

@pboguslawski what realy would help us is some docker-compose with such an auth-proxy in it ...
or an easy description how to set it up

so we can test it and play around with it

@pboguslawski
Copy link
Copy Markdown
Contributor Author

Providing container infrastructure setup script/description for header auth is not easy, requires time and is outside the scope of this PR (feel free to create separate issue if required).

For simple tests consider setting WOODPECKER_GITEA_REV_PROXY_AUTH_HEADER=X-Forward-Username and sending request using curl like this

curl --header 'X-Forward-Username: mylogin' http://127.0.0.1:1234

or using your favourite proxy (i.e. apache, nginx, haproxy) in front of woodpecker + gitea backends with hardcoded X-Forward-Username: mylogin HTTP header injecting before passing request to backend (authenticated user simulation).

Comment thread cmd/server/server.go
Comment thread docs/docs/30-administration/11-vcs/30-gitea.md Outdated
Comment thread docs/docs/30-administration/11-vcs/30-gitea.md Outdated
pboguslawski and others added 2 commits April 21, 2023 07:33
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
@6543
Copy link
Copy Markdown
Member

6543 commented Apr 21, 2023

CI failed :/ (lint issue)

Copy link
Copy Markdown
Member

@anbraten anbraten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OAuth2 works just fine. As miss-configurations of the reverse proxy setup could lead to some serious security issues I will close this PR now. Anyways Thanks for your work.

@anbraten anbraten closed this May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve existing features forge/gitea gitea forge related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants