-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
cmd: add option to get and set policy directly from database #2765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd: add option to get and set policy directly from database #2765
Conversation
071368c to
729e306
Compare
cmd/headscale/cli/policy.go
Outdated
| 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?") { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
Signed-off-by: Kristoffer Dalby <[email protected]>
Signed-off-by: Kristoffer Dalby <[email protected]>
729e306 to
2372827
Compare
nblock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works now.
this commit adds a new
--bypass-grpc-access-and-database-directlyflag toheadscale policy get|setwhich 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