mirror of
https://github.com/fosrl/newt.git
synced 2026-03-26 20:46:41 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2600b0dab | ||
|
|
1656141599 | ||
|
|
1bf89a2cc9 | ||
|
|
555e1ddc7c | ||
|
|
514c94519e | ||
|
|
1a3eaedfa5 | ||
|
|
01e2ba31b7 | ||
|
|
556be90b7e | ||
|
|
5d04be92f7 | ||
|
|
60dac98514 | ||
|
|
759e4c5bac | ||
|
|
8609be130e | ||
|
|
e06b8de0a7 | ||
|
|
0af6fb8fef | ||
|
|
9526768dfe | ||
|
|
051ab6ca9d |
@@ -1,4 +1,5 @@
|
|||||||
FROM golang:1.25-alpine AS builder
|
# FROM golang:1.25-alpine AS builder
|
||||||
|
FROM public.ecr.aws/docker/library/golang:1.25-alpine AS builder
|
||||||
|
|
||||||
# Install git and ca-certificates
|
# Install git and ca-certificates
|
||||||
RUN apk --no-cache add ca-certificates git tzdata
|
RUN apk --no-cache add ca-certificates git tzdata
|
||||||
@@ -18,7 +19,7 @@ COPY . .
|
|||||||
# Build the application
|
# Build the application
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /newt
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /newt
|
||||||
|
|
||||||
FROM alpine:3.23 AS runner
|
FROM public.ecr.aws/docker/library/alpine:3.23 AS runner
|
||||||
|
|
||||||
RUN apk --no-cache add ca-certificates tzdata iputils
|
RUN apk --no-cache add ca-certificates tzdata iputils
|
||||||
|
|
||||||
|
|||||||
@@ -46,11 +46,12 @@ func startAuthDaemon(ctx context.Context) error {
|
|||||||
|
|
||||||
// Create auth daemon server
|
// Create auth daemon server
|
||||||
cfg := authdaemon.Config{
|
cfg := authdaemon.Config{
|
||||||
DisableHTTPS: true, // We run without HTTP server in newt
|
DisableHTTPS: true, // We run without HTTP server in newt
|
||||||
PresharedKey: "this-key-is-not-used", // Not used in embedded mode, but set to non-empty to satisfy validation
|
PresharedKey: "this-key-is-not-used", // Not used in embedded mode, but set to non-empty to satisfy validation
|
||||||
PrincipalsFilePath: principalsFile,
|
PrincipalsFilePath: principalsFile,
|
||||||
CACertPath: caCertPath,
|
CACertPath: caCertPath,
|
||||||
Force: true,
|
Force: true,
|
||||||
|
GenerateRandomPassword: authDaemonGenerateRandomPassword,
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, err := authdaemon.NewServer(cfg)
|
srv, err := authdaemon.NewServer(cfg)
|
||||||
@@ -72,8 +73,6 @@ func startAuthDaemon(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// runPrincipalsCmd executes the principals subcommand logic
|
// runPrincipalsCmd executes the principals subcommand logic
|
||||||
func runPrincipalsCmd(args []string) {
|
func runPrincipalsCmd(args []string) {
|
||||||
opts := struct {
|
opts := struct {
|
||||||
@@ -148,4 +147,4 @@ Example:
|
|||||||
newt principals --username alice
|
newt principals --username alice
|
||||||
|
|
||||||
`, defaultPrincipalsPath)
|
`, defaultPrincipalsPath)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
// ProcessConnection runs the same logic as POST /connection: CA cert, user create/reconcile, principals.
|
// ProcessConnection runs the same logic as POST /connection: CA cert, user create/reconcile, principals.
|
||||||
// Use this when DisableHTTPS is true (e.g. embedded in Newt) instead of calling the API.
|
// Use this when DisableHTTPS is true (e.g. embedded in Newt) instead of calling the API.
|
||||||
func (s *Server) ProcessConnection(req ConnectionRequest) {
|
func (s *Server) ProcessConnection(req ConnectionRequest) {
|
||||||
logger.Info("connection: niceId=%q username=%q metadata.sudo=%v metadata.homedir=%v",
|
logger.Info("connection: niceId=%q username=%q metadata.sudoMode=%q metadata.sudoCommands=%v metadata.homedir=%v metadata.groups=%v",
|
||||||
req.NiceId, req.Username, req.Metadata.Sudo, req.Metadata.Homedir)
|
req.NiceId, req.Username, req.Metadata.SudoMode, req.Metadata.SudoCommands, req.Metadata.Homedir, req.Metadata.Groups)
|
||||||
|
|
||||||
cfg := &s.cfg
|
cfg := &s.cfg
|
||||||
if cfg.CACertPath != "" {
|
if cfg.CACertPath != "" {
|
||||||
@@ -16,7 +16,7 @@ func (s *Server) ProcessConnection(req ConnectionRequest) {
|
|||||||
logger.Warn("auth-daemon: write CA cert: %v", err)
|
logger.Warn("auth-daemon: write CA cert: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ensureUser(req.Username, req.Metadata); err != nil {
|
if err := ensureUser(req.Username, req.Metadata, s.cfg.GenerateRandomPassword); err != nil {
|
||||||
logger.Warn("auth-daemon: ensure user: %v", err)
|
logger.Warn("auth-daemon: ensure user: %v", err)
|
||||||
}
|
}
|
||||||
if cfg.PrincipalsFilePath != "" {
|
if cfg.PrincipalsFilePath != "" {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ package authdaemon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -122,8 +124,73 @@ func sudoGroup() string {
|
|||||||
return "sudo"
|
return "sudo"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setRandomPassword generates a random password and sets it for username via chpasswd.
|
||||||
|
// Used when GenerateRandomPassword is true so SSH with PermitEmptyPasswords no can accept the user.
|
||||||
|
func setRandomPassword(username string) error {
|
||||||
|
b := make([]byte, 16)
|
||||||
|
if _, err := rand.Read(b); err != nil {
|
||||||
|
return fmt.Errorf("generate password: %w", err)
|
||||||
|
}
|
||||||
|
password := hex.EncodeToString(b)
|
||||||
|
cmd := exec.Command("chpasswd")
|
||||||
|
cmd.Stdin = strings.NewReader(username + ":" + password)
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
return fmt.Errorf("chpasswd: %w (output: %s)", err, string(out))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const skelDir = "/etc/skel"
|
||||||
|
|
||||||
|
// copySkelInto copies files from srcDir (e.g. /etc/skel) into dstDir (e.g. user's home).
|
||||||
|
// Only creates files that don't already exist. All created paths are chowned to uid:gid.
|
||||||
|
func copySkelInto(srcDir, dstDir string, uid, gid int) {
|
||||||
|
entries, err := os.ReadDir(srcDir)
|
||||||
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
logger.Warn("auth-daemon: read %s: %v", srcDir, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, e := range entries {
|
||||||
|
name := e.Name()
|
||||||
|
src := filepath.Join(srcDir, name)
|
||||||
|
dst := filepath.Join(dstDir, name)
|
||||||
|
if e.IsDir() {
|
||||||
|
if st, err := os.Stat(dst); err == nil && st.IsDir() {
|
||||||
|
copySkelInto(src, dst, uid, gid)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll(dst, 0755); err != nil {
|
||||||
|
logger.Warn("auth-daemon: mkdir %s: %v", dst, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := os.Chown(dst, uid, gid); err != nil {
|
||||||
|
logger.Warn("auth-daemon: chown %s: %v", dst, err)
|
||||||
|
}
|
||||||
|
copySkelInto(src, dst, uid, gid)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(dst); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(src)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("auth-daemon: read %s: %v", src, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(dst, data, 0644); err != nil {
|
||||||
|
logger.Warn("auth-daemon: write %s: %v", dst, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := os.Chown(dst, uid, gid); err != nil {
|
||||||
|
logger.Warn("auth-daemon: chown %s: %v", dst, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ensureUser creates the system user if missing, or reconciles sudo and homedir to match meta.
|
// ensureUser creates the system user if missing, or reconciles sudo and homedir to match meta.
|
||||||
func ensureUser(username string, meta ConnectionMetadata) error {
|
func ensureUser(username string, meta ConnectionMetadata, generateRandomPassword bool) error {
|
||||||
if username == "" {
|
if username == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -132,12 +199,49 @@ func ensureUser(username string, meta ConnectionMetadata) error {
|
|||||||
if _, ok := err.(user.UnknownUserError); !ok {
|
if _, ok := err.(user.UnknownUserError); !ok {
|
||||||
return fmt.Errorf("lookup user %s: %w", username, err)
|
return fmt.Errorf("lookup user %s: %w", username, err)
|
||||||
}
|
}
|
||||||
return createUser(username, meta)
|
return createUser(username, meta, generateRandomPassword)
|
||||||
}
|
}
|
||||||
return reconcileUser(u, meta)
|
return reconcileUser(u, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(username string, meta ConnectionMetadata) error {
|
// desiredGroups returns the exact list of supplementary groups the user should have:
|
||||||
|
// meta.Groups plus the sudo group when meta.SudoMode is "full" (deduped).
|
||||||
|
func desiredGroups(meta ConnectionMetadata) []string {
|
||||||
|
seen := make(map[string]struct{})
|
||||||
|
var out []string
|
||||||
|
for _, g := range meta.Groups {
|
||||||
|
g = strings.TrimSpace(g)
|
||||||
|
if g == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := seen[g]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[g] = struct{}{}
|
||||||
|
out = append(out, g)
|
||||||
|
}
|
||||||
|
if meta.SudoMode == "full" {
|
||||||
|
sg := sudoGroup()
|
||||||
|
if _, ok := seen[sg]; !ok {
|
||||||
|
out = append(out, sg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// setUserGroups sets the user's supplementary groups to exactly groups (local mirrors metadata).
|
||||||
|
// When groups is empty, clears all supplementary groups (usermod -G "").
|
||||||
|
func setUserGroups(username string, groups []string) {
|
||||||
|
list := strings.Join(groups, ",")
|
||||||
|
cmd := exec.Command("usermod", "-G", list, username)
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
logger.Warn("auth-daemon: usermod -G %s: %v (output: %s)", list, err, string(out))
|
||||||
|
} else {
|
||||||
|
logger.Info("auth-daemon: set %s supplementary groups to %s", username, list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createUser(username string, meta ConnectionMetadata, generateRandomPassword bool) error {
|
||||||
args := []string{"-s", "/bin/bash"}
|
args := []string{"-s", "/bin/bash"}
|
||||||
if meta.Homedir {
|
if meta.Homedir {
|
||||||
args = append(args, "-m")
|
args = append(args, "-m")
|
||||||
@@ -150,75 +254,143 @@ func createUser(username string, meta ConnectionMetadata) error {
|
|||||||
return fmt.Errorf("useradd %s: %w (output: %s)", username, err, string(out))
|
return fmt.Errorf("useradd %s: %w (output: %s)", username, err, string(out))
|
||||||
}
|
}
|
||||||
logger.Info("auth-daemon: created user %s (homedir=%v)", username, meta.Homedir)
|
logger.Info("auth-daemon: created user %s (homedir=%v)", username, meta.Homedir)
|
||||||
if meta.Sudo {
|
if generateRandomPassword {
|
||||||
group := sudoGroup()
|
if err := setRandomPassword(username); err != nil {
|
||||||
cmd := exec.Command("usermod", "-aG", group, username)
|
logger.Warn("auth-daemon: set random password for %s: %v", username, err)
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
logger.Warn("auth-daemon: usermod -aG %s %s: %v (output: %s)", group, username, err, string(out))
|
|
||||||
} else {
|
} else {
|
||||||
logger.Info("auth-daemon: added %s to %s", username, group)
|
logger.Info("auth-daemon: set random password for %s (PermitEmptyPasswords no)", username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if meta.Homedir {
|
||||||
|
if u, err := user.Lookup(username); err == nil && u.HomeDir != "" {
|
||||||
|
uid, gid := mustAtoi(u.Uid), mustAtoi(u.Gid)
|
||||||
|
copySkelInto(skelDir, u.HomeDir, uid, gid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setUserGroups(username, desiredGroups(meta))
|
||||||
|
switch meta.SudoMode {
|
||||||
|
case "full":
|
||||||
|
if err := configurePasswordlessSudo(username); err != nil {
|
||||||
|
logger.Warn("auth-daemon: configure passwordless sudo for %s: %v", username, err)
|
||||||
|
}
|
||||||
|
case "commands":
|
||||||
|
if len(meta.SudoCommands) > 0 {
|
||||||
|
if err := configureSudoCommands(username, meta.SudoCommands); err != nil {
|
||||||
|
logger.Warn("auth-daemon: configure sudo commands for %s: %v", username, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
removeSudoers(username)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sudoersFilePrefix = "90-pangolin-"
|
||||||
|
|
||||||
|
func sudoersPath(username string) string {
|
||||||
|
return filepath.Join("/etc/sudoers.d", sudoersFilePrefix+username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeSudoersFile writes content to the user's sudoers.d file and validates with visudo.
|
||||||
|
func writeSudoersFile(username, content string) error {
|
||||||
|
sudoersFile := sudoersPath(username)
|
||||||
|
tmpFile := sudoersFile + ".tmp"
|
||||||
|
if err := os.WriteFile(tmpFile, []byte(content), 0440); err != nil {
|
||||||
|
return fmt.Errorf("write temp sudoers file: %w", err)
|
||||||
|
}
|
||||||
|
cmd := exec.Command("visudo", "-c", "-f", tmpFile)
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
os.Remove(tmpFile)
|
||||||
|
return fmt.Errorf("visudo validation failed: %w (output: %s)", err, string(out))
|
||||||
|
}
|
||||||
|
if err := os.Rename(tmpFile, sudoersFile); err != nil {
|
||||||
|
os.Remove(tmpFile)
|
||||||
|
return fmt.Errorf("move sudoers file: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// configurePasswordlessSudo creates a sudoers.d file to allow passwordless sudo for the user.
|
||||||
|
func configurePasswordlessSudo(username string) error {
|
||||||
|
content := fmt.Sprintf("# Created by Pangolin auth-daemon\n%s ALL=(ALL) NOPASSWD:ALL\n", username)
|
||||||
|
if err := writeSudoersFile(username, content); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("auth-daemon: configured passwordless sudo for %s", username)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// configureSudoCommands creates a sudoers.d file allowing only the listed commands (NOPASSWD).
|
||||||
|
// Each command should be a full path (e.g. /usr/bin/systemctl).
|
||||||
|
func configureSudoCommands(username string, commands []string) error {
|
||||||
|
var b strings.Builder
|
||||||
|
b.WriteString("# Created by Pangolin auth-daemon (restricted commands)\n")
|
||||||
|
n := 0
|
||||||
|
for _, c := range commands {
|
||||||
|
c = strings.TrimSpace(c)
|
||||||
|
if c == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&b, "%s ALL=(ALL) NOPASSWD: %s\n", username, c)
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
if n == 0 {
|
||||||
|
return fmt.Errorf("no valid sudo commands")
|
||||||
|
}
|
||||||
|
if err := writeSudoersFile(username, b.String()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logger.Info("auth-daemon: configured restricted sudo for %s (%d commands)", username, len(commands))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// removeSudoers removes the sudoers.d file for the user.
|
||||||
|
func removeSudoers(username string) {
|
||||||
|
sudoersFile := sudoersPath(username)
|
||||||
|
if err := os.Remove(sudoersFile); err != nil && !os.IsNotExist(err) {
|
||||||
|
logger.Warn("auth-daemon: remove sudoers for %s: %v", username, err)
|
||||||
|
} else if err == nil {
|
||||||
|
logger.Info("auth-daemon: removed sudoers for %s", username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func mustAtoi(s string) int {
|
func mustAtoi(s string) int {
|
||||||
n, _ := strconv.Atoi(s)
|
n, _ := strconv.Atoi(s)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func reconcileUser(u *user.User, meta ConnectionMetadata) error {
|
func reconcileUser(u *user.User, meta ConnectionMetadata) error {
|
||||||
group := sudoGroup()
|
setUserGroups(u.Username, desiredGroups(meta))
|
||||||
inGroup, err := userInGroup(u.Username, group)
|
switch meta.SudoMode {
|
||||||
if err != nil {
|
case "full":
|
||||||
logger.Warn("auth-daemon: check group %s: %v", group, err)
|
if err := configurePasswordlessSudo(u.Username); err != nil {
|
||||||
inGroup = false
|
logger.Warn("auth-daemon: configure passwordless sudo for %s: %v", u.Username, err)
|
||||||
}
|
|
||||||
if meta.Sudo && !inGroup {
|
|
||||||
cmd := exec.Command("usermod", "-aG", group, u.Username)
|
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
logger.Warn("auth-daemon: usermod -aG %s %s: %v (output: %s)", group, u.Username, err, string(out))
|
|
||||||
} else {
|
|
||||||
logger.Info("auth-daemon: added %s to %s", u.Username, group)
|
|
||||||
}
|
}
|
||||||
} else if !meta.Sudo && inGroup {
|
case "commands":
|
||||||
cmd := exec.Command("gpasswd", "-d", u.Username, group)
|
if len(meta.SudoCommands) > 0 {
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
if err := configureSudoCommands(u.Username, meta.SudoCommands); err != nil {
|
||||||
logger.Warn("auth-daemon: gpasswd -d %s %s: %v (output: %s)", u.Username, group, err, string(out))
|
logger.Warn("auth-daemon: configure sudo commands for %s: %v", u.Username, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Info("auth-daemon: removed %s from %s", u.Username, group)
|
removeSudoers(u.Username)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
removeSudoers(u.Username)
|
||||||
}
|
}
|
||||||
if meta.Homedir && u.HomeDir != "" {
|
if meta.Homedir && u.HomeDir != "" {
|
||||||
|
uid, gid := mustAtoi(u.Uid), mustAtoi(u.Gid)
|
||||||
if st, err := os.Stat(u.HomeDir); err != nil || !st.IsDir() {
|
if st, err := os.Stat(u.HomeDir); err != nil || !st.IsDir() {
|
||||||
if err := os.MkdirAll(u.HomeDir, 0755); err != nil {
|
if err := os.MkdirAll(u.HomeDir, 0755); err != nil {
|
||||||
logger.Warn("auth-daemon: mkdir %s: %v", u.HomeDir, err)
|
logger.Warn("auth-daemon: mkdir %s: %v", u.HomeDir, err)
|
||||||
} else {
|
} else {
|
||||||
uid, gid := mustAtoi(u.Uid), mustAtoi(u.Gid)
|
|
||||||
_ = os.Chown(u.HomeDir, uid, gid)
|
_ = os.Chown(u.HomeDir, uid, gid)
|
||||||
|
copySkelInto(skelDir, u.HomeDir, uid, gid)
|
||||||
logger.Info("auth-daemon: created home %s for %s", u.HomeDir, u.Username)
|
logger.Info("auth-daemon: created home %s for %s", u.HomeDir, u.Username)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Ensure .bashrc etc. exist (e.g. home existed but was empty or skel was minimal)
|
||||||
|
copySkelInto(skelDir, u.HomeDir, uid, gid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func userInGroup(username, groupName string) (bool, error) {
|
|
||||||
// getent group wheel returns "wheel:x:10:user1,user2"
|
|
||||||
cmd := exec.Command("getent", "group", groupName)
|
|
||||||
out, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
parts := strings.SplitN(strings.TrimSpace(string(out)), ":", 4)
|
|
||||||
if len(parts) < 4 {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
members := strings.Split(parts[3], ",")
|
|
||||||
for _, m := range members {
|
|
||||||
if strings.TrimSpace(m) == username {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func writeCACertIfNotExists(path, contents string, force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensureUser returns an error on non-Linux.
|
// ensureUser returns an error on non-Linux.
|
||||||
func ensureUser(username string, meta ConnectionMetadata) error {
|
func ensureUser(username string, meta ConnectionMetadata, generateRandomPassword bool) error {
|
||||||
return errLinuxOnly
|
return errLinuxOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ func (s *Server) registerRoutes() {
|
|||||||
|
|
||||||
// ConnectionMetadata is the metadata object in POST /connection.
|
// ConnectionMetadata is the metadata object in POST /connection.
|
||||||
type ConnectionMetadata struct {
|
type ConnectionMetadata struct {
|
||||||
Sudo bool `json:"sudo"`
|
SudoMode string `json:"sudoMode"` // "none" | "full" | "commands"
|
||||||
Homedir bool `json:"homedir"`
|
SudoCommands []string `json:"sudoCommands"` // used when sudoMode is "commands"
|
||||||
|
Homedir bool `json:"homedir"`
|
||||||
|
Groups []string `json:"groups"` // system groups to add the user to
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectionRequest is the JSON body for POST /connection.
|
// ConnectionRequest is the JSON body for POST /connection.
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ type Config struct {
|
|||||||
Port int // Required when DisableHTTPS is false. Listen port for the HTTPS server. No default.
|
Port int // Required when DisableHTTPS is false. Listen port for the HTTPS server. No default.
|
||||||
PresharedKey string // Required when DisableHTTPS is false. HTTP auth (Authorization: Bearer <key> or X-Preshared-Key: <key>). No default.
|
PresharedKey string // Required when DisableHTTPS is false. HTTP auth (Authorization: Bearer <key> or X-Preshared-Key: <key>). No default.
|
||||||
CACertPath string // Required. Where to write the CA cert (e.g. /etc/ssh/ca.pem). No default.
|
CACertPath string // Required. Where to write the CA cert (e.g. /etc/ssh/ca.pem). No default.
|
||||||
Force bool // If true, overwrite existing CA cert (and other items) when content differs. Default false.
|
Force bool // If true, overwrite existing CA cert (and other items) when content differs. Default false.
|
||||||
PrincipalsFilePath string // Required. Path to the principals data file (JSON: username -> array of principals). No default.
|
PrincipalsFilePath string // Required. Path to the principals data file (JSON: username -> array of principals). No default.
|
||||||
|
GenerateRandomPassword bool // If true, set a random password on users when they are provisioned (for SSH PermitEmptyPasswords no).
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|||||||
47
main.go
47
main.go
@@ -116,6 +116,7 @@ var (
|
|||||||
logLevel string
|
logLevel string
|
||||||
interfaceName string
|
interfaceName string
|
||||||
port uint16
|
port uint16
|
||||||
|
portStr string
|
||||||
disableClients bool
|
disableClients bool
|
||||||
updownScript string
|
updownScript string
|
||||||
dockerSocket string
|
dockerSocket string
|
||||||
@@ -136,6 +137,7 @@ var (
|
|||||||
authDaemonPrincipalsFile string
|
authDaemonPrincipalsFile string
|
||||||
authDaemonCACertPath string
|
authDaemonCACertPath string
|
||||||
authDaemonEnabled bool
|
authDaemonEnabled bool
|
||||||
|
authDaemonGenerateRandomPassword bool
|
||||||
// Build/version (can be overridden via -ldflags "-X main.newtVersion=...")
|
// Build/version (can be overridden via -ldflags "-X main.newtVersion=...")
|
||||||
newtVersion = "version_replaceme"
|
newtVersion = "version_replaceme"
|
||||||
|
|
||||||
@@ -210,11 +212,12 @@ func runNewtMain(ctx context.Context) {
|
|||||||
logLevel = os.Getenv("LOG_LEVEL")
|
logLevel = os.Getenv("LOG_LEVEL")
|
||||||
updownScript = os.Getenv("UPDOWN_SCRIPT")
|
updownScript = os.Getenv("UPDOWN_SCRIPT")
|
||||||
interfaceName = os.Getenv("INTERFACE")
|
interfaceName = os.Getenv("INTERFACE")
|
||||||
portStr := os.Getenv("PORT")
|
portStr = os.Getenv("PORT")
|
||||||
authDaemonKey = os.Getenv("AD_KEY")
|
authDaemonKey = os.Getenv("AD_KEY")
|
||||||
authDaemonPrincipalsFile = os.Getenv("AD_PRINCIPALS_FILE")
|
authDaemonPrincipalsFile = os.Getenv("AD_PRINCIPALS_FILE")
|
||||||
authDaemonCACertPath = os.Getenv("AD_CA_CERT_PATH")
|
authDaemonCACertPath = os.Getenv("AD_CA_CERT_PATH")
|
||||||
authDaemonEnabledEnv := os.Getenv("AUTH_DAEMON_ENABLED")
|
authDaemonEnabledEnv := os.Getenv("AUTH_DAEMON_ENABLED")
|
||||||
|
authDaemonGenerateRandomPasswordEnv := os.Getenv("AD_GENERATE_RANDOM_PASSWORD")
|
||||||
|
|
||||||
// Metrics/observability env mirrors
|
// Metrics/observability env mirrors
|
||||||
metricsEnabledEnv := os.Getenv("NEWT_METRICS_PROMETHEUS_ENABLED")
|
metricsEnabledEnv := os.Getenv("NEWT_METRICS_PROMETHEUS_ENABLED")
|
||||||
@@ -420,6 +423,13 @@ func runNewtMain(ctx context.Context) {
|
|||||||
authDaemonEnabled = v
|
authDaemonEnabled = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if authDaemonGenerateRandomPasswordEnv == "" {
|
||||||
|
flag.BoolVar(&authDaemonGenerateRandomPassword, "ad-generate-random-password", false, "Generate a random password for authenticated users")
|
||||||
|
} else {
|
||||||
|
if v, err := strconv.ParseBool(authDaemonGenerateRandomPasswordEnv); err == nil {
|
||||||
|
authDaemonGenerateRandomPassword = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// do a --version check
|
// do a --version check
|
||||||
version := flag.Bool("version", false, "Print the version")
|
version := flag.Bool("version", false, "Print the version")
|
||||||
@@ -1378,15 +1388,18 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
|
|
||||||
// Define the structure of the incoming message
|
// Define the structure of the incoming message
|
||||||
type SSHCertData struct {
|
type SSHCertData struct {
|
||||||
MessageId int `json:"messageId"`
|
MessageId int `json:"messageId"`
|
||||||
AgentPort int `json:"agentPort"`
|
AgentPort int `json:"agentPort"`
|
||||||
AgentHost string `json:"agentHost"`
|
AgentHost string `json:"agentHost"`
|
||||||
CACert string `json:"caCert"`
|
ExternalAuthDaemon bool `json:"externalAuthDaemon"`
|
||||||
Username string `json:"username"`
|
CACert string `json:"caCert"`
|
||||||
NiceID string `json:"niceId"`
|
Username string `json:"username"`
|
||||||
Metadata struct {
|
NiceID string `json:"niceId"`
|
||||||
Sudo bool `json:"sudo"`
|
Metadata struct {
|
||||||
Homedir bool `json:"homedir"`
|
SudoMode string `json:"sudoMode"`
|
||||||
|
SudoCommands []string `json:"sudoCommands"`
|
||||||
|
Homedir bool `json:"homedir"`
|
||||||
|
Groups []string `json:"groups"`
|
||||||
} `json:"metadata"`
|
} `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1406,7 +1419,7 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we're running the auth daemon internally
|
// Check if we're running the auth daemon internally
|
||||||
if authDaemonServer != nil {
|
if authDaemonServer != nil && !certData.ExternalAuthDaemon { // if the auth daemon is running internally and the external auth daemon is not enabled
|
||||||
// Call ProcessConnection directly when running internally
|
// Call ProcessConnection directly when running internally
|
||||||
logger.Debug("Calling internal auth daemon ProcessConnection for user %s", certData.Username)
|
logger.Debug("Calling internal auth daemon ProcessConnection for user %s", certData.Username)
|
||||||
|
|
||||||
@@ -1415,8 +1428,10 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
NiceId: certData.NiceID,
|
NiceId: certData.NiceID,
|
||||||
Username: certData.Username,
|
Username: certData.Username,
|
||||||
Metadata: authdaemon.ConnectionMetadata{
|
Metadata: authdaemon.ConnectionMetadata{
|
||||||
Sudo: certData.Metadata.Sudo,
|
SudoMode: certData.Metadata.SudoMode,
|
||||||
Homedir: certData.Metadata.Homedir,
|
SudoCommands: certData.Metadata.SudoCommands,
|
||||||
|
Homedir: certData.Metadata.Homedir,
|
||||||
|
Groups: certData.Metadata.Groups,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1450,8 +1465,10 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
"niceId": certData.NiceID,
|
"niceId": certData.NiceID,
|
||||||
"username": certData.Username,
|
"username": certData.Username,
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"sudo": certData.Metadata.Sudo,
|
"sudoMode": certData.Metadata.SudoMode,
|
||||||
"homedir": certData.Metadata.Homedir,
|
"sudoCommands": certData.Metadata.SudoCommands,
|
||||||
|
"homedir": certData.Metadata.Homedir,
|
||||||
|
"groups": certData.Metadata.Groups,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
newt.iss
2
newt.iss
@@ -32,7 +32,7 @@ DefaultGroupName={#MyAppName}
|
|||||||
DisableProgramGroupPage=yes
|
DisableProgramGroupPage=yes
|
||||||
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
||||||
;PrivilegesRequired=lowest
|
;PrivilegesRequired=lowest
|
||||||
OutputBaseFilename=mysetup
|
OutputBaseFilename=newt_windows_installer
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
||||||
|
|||||||
Reference in New Issue
Block a user