mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-13 11:09:10 +08:00
52a323b90d
Advertises the SSH capability, and parses the SSH ACLs to pass to the tailscale client. Doesn’t support ‘autogroup’ ACL functionality. Co-authored-by: Daniel Brooks <db48x@headline.com>
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package headscale
|
|
|
|
import (
|
|
"github.com/rs/zerolog/log"
|
|
"tailscale.com/tailcfg"
|
|
)
|
|
|
|
func (h *Headscale) generateMapResponse(
|
|
mapRequest tailcfg.MapRequest,
|
|
machine *Machine,
|
|
) (*tailcfg.MapResponse, error) {
|
|
log.Trace().
|
|
Str("func", "generateMapResponse").
|
|
Str("machine", mapRequest.Hostinfo.Hostname).
|
|
Msg("Creating Map response")
|
|
node, err := machine.toNode(h.cfg.BaseDomain, h.cfg.DNSConfig)
|
|
if err != nil {
|
|
log.Error().
|
|
Caller().
|
|
Str("func", "generateMapResponse").
|
|
Err(err).
|
|
Msg("Cannot convert to node")
|
|
|
|
return nil, err
|
|
}
|
|
|
|
peers, err := h.getValidPeers(machine)
|
|
if err != nil {
|
|
log.Error().
|
|
Caller().
|
|
Str("func", "generateMapResponse").
|
|
Err(err).
|
|
Msg("Cannot fetch peers")
|
|
|
|
return nil, err
|
|
}
|
|
|
|
profiles := h.getMapResponseUserProfiles(*machine, peers)
|
|
|
|
nodePeers, err := peers.toNodes(h.cfg.BaseDomain, h.cfg.DNSConfig)
|
|
if err != nil {
|
|
log.Error().
|
|
Caller().
|
|
Str("func", "generateMapResponse").
|
|
Err(err).
|
|
Msg("Failed to convert peers to Tailscale nodes")
|
|
|
|
return nil, err
|
|
}
|
|
|
|
dnsConfig := getMapResponseDNSConfig(
|
|
h.cfg.DNSConfig,
|
|
h.cfg.BaseDomain,
|
|
*machine,
|
|
peers,
|
|
)
|
|
|
|
resp := tailcfg.MapResponse{
|
|
KeepAlive: false,
|
|
Node: node,
|
|
Peers: nodePeers,
|
|
DNSConfig: dnsConfig,
|
|
Domain: h.cfg.BaseDomain,
|
|
PacketFilter: h.aclRules,
|
|
SSHPolicy: h.sshPolicy,
|
|
DERPMap: h.DERPMap,
|
|
UserProfiles: profiles,
|
|
Debug: &tailcfg.Debug{
|
|
DisableLogTail: !h.cfg.LogTail.Enabled,
|
|
RandomizeClientPort: h.cfg.RandomizeClientPort,
|
|
},
|
|
}
|
|
|
|
log.Trace().
|
|
Str("func", "generateMapResponse").
|
|
Str("machine", mapRequest.Hostinfo.Hostname).
|
|
// Interface("payload", resp).
|
|
Msgf("Generated map response: %s", tailMapResponseToString(resp))
|
|
|
|
return &resp, nil
|
|
}
|