Skip to content

Commit

Permalink
Add caddyfile parsing for allowing tagged nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Christine Dodrill <xe@tailscale.com>
  • Loading branch information
Christine Dodrill committed Oct 27, 2022
1 parent a98aa89 commit c2ec606
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tscaddy

import (
"fmt"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -89,6 +90,8 @@ func getListener(_, addr string) (net.Listener, error) {

type TailscaleAuth struct {
localclient *tailscale.LocalClient

AllowTaggedNodes bool `json:"allow_tagged_nodes"`
}

func (TailscaleAuth) CaddyModule() caddy.ModuleInfo {
Expand Down Expand Up @@ -144,9 +147,11 @@ func (ta TailscaleAuth) Authenticate(w http.ResponseWriter, r *http.Request) (ca
return user, false, err
}

if len(info.Node.Tags) != 0 {
if ta.AllowTaggedNodes && len(info.Node.Tags) != 0 {
info.UserProfile.LoginName = strings.Replace(info.Node.Tags[0], ":", "___", -1) + "@tags.in.your.tailnet"
info.UserProfile.DisplayName = "A tagged node with tags: " + strings.Join(info.Node.Tags, ", ")
} else {
return user, false, fmt.Errorf("node %s has tags", info.Node.Hostinfo.Hostname())
}

var tailnet string
Expand Down

1 comment on commit c2ec606

@gbraad
Copy link

@gbraad gbraad commented on c2ec606 Apr 29, 2023

Choose a reason for hiding this comment

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

👍

Please sign in to comment.