Skip to content

Conversation

@kradalby
Copy link
Collaborator

this commit adds a new --bypass-grpc-access-and-database-directly flag to headscale policy get|set which allows the operator to directly get or set the policy from the database. This is useful if there is a broken policy in the database that prevents the server from starting.

Fixes #2630

@kradalby kradalby force-pushed the kradalby/acl-startup-invalid branch 3 times, most recently from 071368c to 729e306 Compare September 11, 2025 14:03
ErrorOutput(err, fmt.Sprintf("Failed loading ACL Policy: %s", err), output)
var policy string
if bypass, _ := cmd.Flags().GetBool(bypassFlag); bypass {
if !prompt.YesNo("DO NOT run this command if an instance of headscale is running, are you sure headscale is not running?") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Headscale crashes when answering the question with n:

$ headscale --force policy get --bypass-grpc-and-access-database-directly
DO NOT run this command if an instance of headscale is running, are you sure headscale is not running? [y/n] n
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x55d04da6fab9]

goroutine 1 [running]:
github.com/juanfont/headscale/cmd/headscale/cli.ErrorOutput({0x0?, 0x0?}, {0x55d04daf69e0, 0x10}, {0x0, 0x0})
        /home/user/headscale/cmd/headscale/cli/utils.go:172 +0x39
github.com/juanfont/headscale/cmd/headscale/cli.init.func21(0x55d0501c3b20, {0x55d04dadff11?, 0x4?, 0x55d04dadfde1?})
        /home/user/headscale/cmd/headscale/cli/policy.go:56 +0x50a
github.com/spf13/cobra.(*Command).execute(0x55d0501c3b20, {0xc00009ca20, 0x2, 0x2})
        /home/user/go/pkg/mod/github.com/spf13/[email protected]/command.go:1019 +0xa91
github.com/spf13/cobra.(*Command).ExecuteC(0x55d0501c4ba0)
        /home/user/go/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x46f
github.com/spf13/cobra.(*Command).Execute(...)
        /home/user/go/pkg/mod/github.com/spf13/[email protected]/command.go:1071
github.com/juanfont/headscale/cmd/headscale/cli.Execute()
        /home/user/headscale/cmd/headscale/cli/root.go:103 +0x1a
main.main()
        /home/user/headscale/cmd/headscale/headscale.go:42 +0x1fe

if err != nil {
ErrorOutput(err, fmt.Sprintf("Failed loading ACL Policy: %s", err), output)
var policy string
if bypass, _ := cmd.Flags().GetBool(bypassFlag); bypass {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The flag does not account for the --force flag.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The interactive question is hidden when redirecting the output to a file:

$ headscale policy get --force --bypass-grpc-and-access-database-directly > dump-1.json
... [hangs and continues only when pressing `y`]

Also the json output contains the question:

$ cat dump-1.json 
DO NOT run this command if an instance of headscale is running, are you sure headscale is not running? [y/n] {
  "acls": [
    {
      "action": "accept",
      "src": [
        "*"
      ],
      "dst": [
        "100.64.0.99"
      ]
    }
  ]
}

Question should be written to stderr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Its possible to set an invalid ACL (or invalid JSON) via: headscale policy set --bypass-grpc-and-access-database-directly --file path/to/broken.json. Should it only allow valid ACLs?

this commit adds a new `--bypass-grpc-and-access-database-directly`
flag to `headscale policy get|set` which allows the operator to
directly get or set the policy from the database. This is useful
if there is a broken policy in the database that prevents the
  server from starting.

Fixes juanfont#2630

Signed-off-by: Kristoffer Dalby <[email protected]>
Signed-off-by: Kristoffer Dalby <[email protected]>
Signed-off-by: Kristoffer Dalby <[email protected]>
@kradalby kradalby force-pushed the kradalby/acl-startup-invalid branch from 729e306 to 2372827 Compare September 12, 2025 14:15
@kradalby kradalby marked this pull request as ready for review September 12, 2025 14:16
Copy link
Collaborator

@nblock nblock left a comment

Choose a reason for hiding this comment

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

Works now.

@kradalby kradalby merged commit 2b30a15 into juanfont:main Sep 12, 2025
80 of 85 checks passed
shouryagautam pushed a commit to shouryagautam/headscale that referenced this pull request Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Invalid ACL stored in DB, crash on startup

3 participants