-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add functionality to Enable/Disable users #782
base: main
Are you sure you want to change the base?
Changes from all commits
7bcc727
5a0c8ea
7db3b90
54b8833
7c8e8f0
f6ad608
7061140
85c7275
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Package main implements Cobra commands for management operations on authd. | ||
package main | ||
|
||
adombeck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/ubuntu/authd/cmd/authctl/user" | ||
) | ||
|
||
const cmdName = "authctl" | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: fmt.Sprintf("%s COMMAND", cmdName), | ||
Short: "CLI tool to interact with authd", | ||
Long: "authctl is a CLI tool which can be used to interact with authd.", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(user.UserCmd) | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(1) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package user | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/ubuntu/authd/internal/consts" | ||
"github.com/ubuntu/authd/internal/proto/authd" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
// disableCmd is a command to disable a user. | ||
var disableCmd = &cobra.Command{ | ||
Use: "disable", | ||
Short: "Disable a user managed by authd", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Printf("Disabling user %q\n", args[0]) | ||
|
||
authdSocket := os.Getenv("AUTHD_SOCKET") | ||
if authdSocket == "" { | ||
authdSocket = "unix://" + consts.DefaultSocketPath | ||
} | ||
|
||
conn, err := grpc.NewClient(authdSocket, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also check for the HealthCheck to be around? See pam adapter model but it can be simpler here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What benefit would that provide here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, do not make the request when the socket is there but not ready (so in a socket-activated scenario) or in tests where the daemon may take some time to show up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmh, I don't really understand how calling the My understanding of the gRPC health checks is that they are useful for two things: monitoring the status of gRPC services and choosing a healthy service from a list of services. Both don't apply to our use case. |
||
client := authd.NewNSSClient(conn) | ||
_, err = client.DisableUser(context.Background(), &authd.DisableUserRequest{Name: args[0]}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package user | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/ubuntu/authd/internal/consts" | ||
"github.com/ubuntu/authd/internal/proto/authd" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
// enableCmd is a command to enable a user. | ||
var enableCmd = &cobra.Command{ | ||
Use: "enable", | ||
Short: "Enable a user managed by authd", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Printf("Enabling user %q\n", args[0]) | ||
|
||
authdSocket := os.Getenv("AUTHD_SOCKET") | ||
if authdSocket == "" { | ||
authdSocket = "unix://" + consts.DefaultSocketPath | ||
} | ||
|
||
conn, err := grpc.NewClient(authdSocket, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := authd.NewNSSClient(conn) | ||
_, err = client.EnableUser(context.Background(), &authd.EnableUserRequest{Name: args[0]}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Package user provides utilities for managing user operations. | ||
package user | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// UserCmd is a command to perform user-related operations. | ||
var UserCmd = &cobra.Command{ | ||
Use: "user", | ||
Short: "Commands related to users", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func init() { | ||
UserCmd.AddCommand(disableCmd) | ||
UserCmd.AddCommand(enableCmd) | ||
} |
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.
It would be nice to have integration tests for this, but if you don't have the time it would be nice if you could open an issue so that we can track it.
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.
What do you want to see tested in these integration tests?
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.
I would like to have tests which start authd and then use authctl and check that it works as expected. That would be an end-to-end test which we don't have a framework for yet. I'm not sure if makes sense to have something in between the tests we already have and this end-to-end test.
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.
Exactly what I mean, and what it should be done IMHO in an integration test, similar to the PAM ones.
Basically, adding a new (VHS based, sorry) test that:
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.
Can you point me to the examples of existing integration tests in the code? I will use them as a reference to write new ones.
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.
But indeed that's marked as locked and so we filtering it out in gdm...
However... What lock does is that eventually calls
usermod -L -- $USER
that indeed would fail for authd users, and so the user wouldn't never be marked as locked either.In fact:
Thus it wouldn't be enough... Account service has support for vendor overrides, but I'm unsure if they can help either
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.
If integration tests are not a blocker to merge this work, can we create another issue for that?