|
|
3 лет назад | |
|---|---|---|
| .. | ||
| deb | fc2f628d4c cmd/nginx-auth: maintainer scripts and tailnet checking (#4460) | 3 лет назад |
| rpm | fc2f628d4c cmd/nginx-auth: maintainer scripts and tailnet checking (#4460) | 3 лет назад |
| .gitignore | 4f1d6c53cb cmd/nginx-auth: create new Tailscale NGINX auth service (#4400) | 3 лет назад |
| README.md | 038d25bd04 cmd/nginx-auth: update Expected-Tailnet documentation (#6055) | 3 лет назад |
| mkdeb.sh | bf7573c9ee cmd/nginx-auth: build for arm64 | 3 лет назад |
| nginx-auth.go | 223713d4a1 tailcfg,all: add and use Node.IsTagged() | 3 лет назад |
| tailscale.nginx-auth.service | 4f1d6c53cb cmd/nginx-auth: create new Tailscale NGINX auth service (#4400) | 3 лет назад |
| tailscale.nginx-auth.socket | 4f1d6c53cb cmd/nginx-auth: create new Tailscale NGINX auth service (#4400) | 3 лет назад |
This is a tool that allows users to use Tailscale Whois authentication with NGINX as a reverse proxy. This allows users that already have a bunch of services hosted on an internal NGINX server to point those domains to the Tailscale IP of the NGINX server and then seamlessly use Tailscale for authentication.
Many thanks to @zrail on Twitter for introducing the basic idea and offering some sample code. This program is based on that sample code with security enhancements. Namely:
In order to protect a service with this tool, do the following in the respective
server block:
Create an authentication location with the internal flag set:
location /auth {
internal;
proxy_pass http://unix:/run/tailscale.nginx-auth.sock;
proxy_pass_request_body off;
proxy_set_header Host $http_host;
proxy_set_header Remote-Addr $remote_addr;
proxy_set_header Remote-Port $remote_port;
proxy_set_header Original-URI $request_uri;
}
Then add the following to the location / block:
auth_request /auth;
auth_request_set $auth_user $upstream_http_tailscale_user;
auth_request_set $auth_name $upstream_http_tailscale_name;
auth_request_set $auth_login $upstream_http_tailscale_login;
auth_request_set $auth_tailnet $upstream_http_tailscale_tailnet;
auth_request_set $auth_profile_picture $upstream_http_tailscale_profile_picture;
proxy_set_header X-Webauth-User "$auth_user";
proxy_set_header X-Webauth-Name "$auth_name";
proxy_set_header X-Webauth-Login "$auth_login";
proxy_set_header X-Webauth-Tailnet "$auth_tailnet";
proxy_set_header X-Webauth-Profile-Picture "$auth_profile_picture";
When this configuration is used with a Go HTTP handler such as this:
http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
e := json.NewEncoder(w)
e.SetIndent("", " ")
e.Encode(r.Header)
})
You will get output like this:
{
"Accept": [
"*/*"
],
"Connection": [
"upgrade"
],
"User-Agent": [
"curl/7.82.0"
],
"X-Webauth-Login": [
"Xe"
],
"X-Webauth-Name": [
"Xe Iaso"
],
"X-Webauth-Profile-Picture": [
"https://avatars.githubusercontent.com/u/529003?v=4"
],
"X-Webauth-Tailnet": [
"cetacean.org.github"
]
"X-Webauth-User": [
"Xe@github"
]
}
The authentication service provides the following headers to decorate your proxied requests:
| Header | Example Value | Description |
|---|---|---|
Tailscale-User |
[email protected] |
The Tailscale username the remote machine is logged in as in user@host form |
Tailscale-Login |
azurediamond |
The user portion of the Tailscale username the remote machine is logged in as |
Tailscale-Name |
Azure Diamond |
The "real name" of the Tailscale user the machine is logged in as |
Tailscale-Profile-Picture |
https://i.kym-cdn.com/photos/images/newsfeed/001/065/963/ae0.png |
The profile picture provided by the Identity Provider your tailnet uses |
Tailscale-Tailnet |
hunter2.net |
The tailnet name |
Most of the time you can set X-Webauth-User to the contents of the
Tailscale-User header, but some services may not accept a username with an @
symbol in it. If this is the case, set X-Webauth-User to the Tailscale-Login
header.
The Tailscale-Tailnet header can help you identify which tailnet the session
is coming from. If you are using node sharing, this can help you make sure that
you aren't giving administrative access to people outside your tailnet.
If you want to prevent node sharing from allowing users to access a service, add
the Expected-Tailnet header to your auth request:
location /auth {
# ...
proxy_set_header Expected-Tailnet "tailnet012345.ts.net";
}
If a user from a different tailnet tries to use that service, this will return a generic "forbidden" error page:
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
You can get the tailnet name from the admin panel.
Install cmd/mkpkg:
cd .. && go install ./mkpkg
Then run ./mkdeb.sh. It will emit a .deb and .rpm package for amd64
machines (Linux uname flag: x86_64). You can add these to your deployment
methods as you see fit.