Skip to content
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

Support for JWT authentication mode in telemetry #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saravanan-i
Copy link

@saravanan-i saravanan-i commented Sep 19, 2023

Why I did it

1)To support JWT client authentication in telemetry dialin mode.
2) Patched gnmi_cli to have only supported streaming options like polling and streaming

How I did it

  1. Used DBus to retrieve roles for an user from host and then to create JWT token using the same.
  2. Removed unsupported streaming option (once) from streaming type

How to verify it

  1. Load Telemetry table (with client authentication mode as cert,password,jwt) using config load
  2. Restart the telemetry docker
  3. Request a new JWT token for admin user using gnoi_client
  4. Observe that telemetry server returns the JWT token with expiry date

Which release branch to backport (provide reason below if selected)

  • 202305

Description for the changelog

Added methods to enable JWT token support in telemetry and patched gnmi_cli to show only the supported streaming types

Dependent Merge Requests:
sonic-net/sonic-buildimage#13142
sonic-net/sonic-host-services#76

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@saravanan-i saravanan-i marked this pull request as draft September 19, 2023 04:44
@saravanan-i saravanan-i changed the title Support for other client authentication modes were added Support for JWT authentication mode in telemetry Sep 19, 2023
@saravanan-i saravanan-i marked this pull request as ready for review September 19, 2023 05:09
@saravanan-i
Copy link
Author

saravanan-i commented Sep 20, 2023

/azpw run sonic-gnmi

@mssonicbld
Copy link

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 152 in repo sonic-net/sonic-gnmi

Comment on lines +52 to +53
var cmd string
cmd = "user_auth_mgmt.retrieve_user_roles"
Copy link
Contributor

Choose a reason for hiding this comment

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

Those two lines can be combined in just one:

	cmd := "user_auth_mgmt.retrieve_user_roles"

host_output := transformer.HostQuery(cmd, username)
if host_output.Err != nil {
glog.Errorf("System user roles host query failed")
return nil,errors.New("Failed to retrieve user roles")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a space after the comma.

if val, _ := host_output.Body[0].(int32); val == 0 {
glog.Infof("Roles retrieved from host")
roles := strings.Split(host_output.Body[1].(string), ",")
return roles,nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a space after the comma.

return roles,nil
} else {
glog.Errorf("Invalid User. no roles")
return nil,errors.New(host_output.Body[1].(string))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a space after the comma.

}

roles, err := GetUserRoles(usr)
roles,err := GetUserRoles(username)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a space after the comma.

clientTypes = flags.NewStringList(&cfg.ClientTypes, []string{gclient.Type})
queryFlag = &flags.StringList{}
- queryType = flag.String("query_type", client.Once.String(), "Type of result, one of: (o, once, p, polling, s, streaming).")
+ queryType = flag.String("query_type", "", "Type of result, one of: (p, polling, s, streaming).")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not to specify the default mode? Say, polling?

if srv.config.UserAuth.Enabled("jwt") {
log.V(1).Info("gNOI: Sonic Authenticate - JWT enabled")
} else {
log.V(1).Info("gNOI: Sonic Authenticate - JWT not enabled"
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax error: missing ) at the end

@@ -159,6 +157,7 @@ func (srv *Server) Refresh(ctx context.Context, req *spb_jwt.RefreshRequest) (*s

token, _, err := JwtAuthenAndAuthor(ctx)
if err != nil {
log.Errorf("gNOI: Sonic Refresh - JWTAuthenandAuthor returned error")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add information what error was returned.

glog.Errorf("System user roles host query failed")
return nil,errors.New("Failed to retrieve user roles")
} else {
if val, _ := host_output.Body[0].(int32); val == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not ignore errors. The condition can look like follows:

if val, ok := host_output.Body[0].(int32); ok && val == 0 {

} else {
if val, _ := host_output.Body[0].(int32); val == 0 {
glog.Infof("Roles retrieved from host")
roles := strings.Split(host_output.Body[1].(string), ",")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not ignore errors. If Body[1] is not a string then the program will panic. Even if this not normally/today possible it might change in the future.

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.

3 participants