Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Add RBAC, gNOI, API Versioning and Bulk Set operations. #61

Merged
Merged
Show file tree
Hide file tree
Changes from 102 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
c5953a6
Add gnoi infra with only time rpc implemented
seiferteric Jun 24, 2020
7918502
Remove unimplemeneted functions from gnoi_client
seiferteric Jun 29, 2020
798cc8f
Remove unimplemented sonic proto, will submit seperate PR for those r…
seiferteric Jun 29, 2020
d477f25
Merge remote-tracking branch 'origin/master' into azure_pr_split_gnoi
seiferteric Jun 29, 2020
ce6cc7e
Make gNOI active only on writable mode
seiferteric Jun 29, 2020
12d4ecf
Merge remote-tracking branch 'origin/master' into azure_pr_split_gnoi
seiferteric Nov 2, 2020
ca48de9
Add basic auth changes
seiferteric Nov 2, 2020
45111db
Fix Makefile
seiferteric Nov 3, 2020
9461a62
Fixes
seiferteric Nov 3, 2020
68d697a
Remove allow_no_client_auth option and instead use ca option to deter…
seiferteric Nov 6, 2020
85c5cdc
Add autheticate call to gNOI function calls
seiferteric Nov 6, 2020
5c35cff
Add client certificate authentication mode
seiferteric Nov 6, 2020
839ec86
Add JWT based authentication and authorization mechanism
seiferteric Nov 6, 2020
6afd332
Add ShowTechSupport gNOI function
seiferteric Nov 6, 2020
0f28d53
Register gNOI System service on gRPC server
seiferteric Nov 6, 2020
b83158d
Merge branch 'azure_pr_split_gnoi' into azure_pr_split_basic_auth
seiferteric Nov 6, 2020
b682b15
Merge branch 'azure_pr_split_basic_auth' into azure_pr_split_cert_auth
seiferteric Nov 6, 2020
57237dd
Merge branch 'azure_pr_split_cert_auth' into azure_pr_split_jwt_auth
seiferteric Nov 6, 2020
01aab03
Register Sonic gnoi service. Remove other Sonic gNOI RPCs until a lat…
seiferteric Nov 6, 2020
0d89aff
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Nov 6, 2020
17e9c43
Update proto and add missing deps
seiferteric Nov 6, 2020
00f8677
Add translib RPC helper function to call from gNOI RPCs
seiferteric Nov 6, 2020
a47f48f
Forgot to add Refresh RPC to proto
seiferteric Nov 25, 2020
496eb3b
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Nov 25, 2020
f164cb3
Add authenticate and refresh rpcs to gnoi client
seiferteric Nov 25, 2020
df7f0b7
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Nov 25, 2020
e18e234
Add showTechSupport rpc to gnoi client
seiferteric Nov 25, 2020
24ceff9
Add copyConfig gNOI RPC
seiferteric Nov 25, 2020
11363ce
Add image mgmt gNOI RPCs
seiferteric Nov 25, 2020
7f0f937
Add image clear neighbors gNOI RPC
seiferteric Nov 25, 2020
a11ff0f
Add client patches
seiferteric Dec 1, 2020
0b79803
Add yang versioning feature
seiferteric Dec 1, 2020
18bf5ba
Pass auth info to translib API calls
seiferteric Dec 1, 2020
4b2797e
Merge branch 'azure_pr_split_basic_auth' into azure_pr_split_cert_auth
seiferteric Dec 1, 2020
11b37d1
Merge branch 'azure_pr_split_cert_auth' into azure_pr_split_jwt_auth
seiferteric Dec 1, 2020
7adfaef
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Dec 1, 2020
3eb2760
Merge branch 'azure_pr_split_show_tech_support' into azure_pr_split_c…
seiferteric Dec 1, 2020
91ebf96
Merge branch 'azure_pr_split_copy_config' into azure_pr_split_image_mgmt
seiferteric Dec 1, 2020
2f7982a
Merge branch 'azure_pr_split_image_mgmt' into azure_pr_split_clear_ne…
seiferteric Dec 1, 2020
b4aebc8
Merge branch 'azure_pr_split_clear_neighbors' into azure_pr_split_cli…
seiferteric Dec 1, 2020
9f2e149
Merge branch 'azure_pr_split_client_patches' into azure_pr_split_yang…
seiferteric Dec 1, 2020
f5d08dd
Add Bulk Set support
seiferteric Dec 1, 2020
caaf792
Add context when creating transl data client for passing authentication
seiferteric Dec 1, 2020
06685e2
Merge branch 'azure_pr_split_basic_auth' into azure_pr_split_cert_auth
seiferteric Dec 1, 2020
edbe598
Merge branch 'azure_pr_split_cert_auth' into azure_pr_split_jwt_auth
seiferteric Dec 1, 2020
f53e119
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Dec 1, 2020
d4f0a83
Merge branch 'azure_pr_split_show_tech_support' into azure_pr_split_c…
seiferteric Dec 1, 2020
e4fb5cf
Merge branch 'azure_pr_split_copy_config' into azure_pr_split_image_mgmt
seiferteric Dec 1, 2020
b483cc4
Merge branch 'azure_pr_split_image_mgmt' into azure_pr_split_clear_ne…
seiferteric Dec 1, 2020
714d9fd
Merge branch 'azure_pr_split_clear_neighbors' into azure_pr_split_cli…
seiferteric Dec 1, 2020
5361c18
Merge branch 'azure_pr_split_client_patches' into azure_pr_split_yang…
seiferteric Dec 1, 2020
6fc5c34
Add extensions list to NewTranslClient
seiferteric Dec 1, 2020
86b6a7c
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 1, 2020
cf37762
Check yang bundle version in all actions
seiferteric Dec 1, 2020
7215655
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 1, 2020
be3cb26
Add yang bundle version check to Bulk set
seiferteric Dec 1, 2020
ba311cf
Update error message
seiferteric Dec 1, 2020
75c8cc6
Use correct operations and fix error messages
seiferteric Dec 1, 2020
47784e9
Add yang version check in TranslSubscribe function
seiferteric Dec 1, 2020
c7740a9
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 1, 2020
2c437d8
Merge branch 'azure_pr_split_bulk_support' into azure_pr_split_fix_up…
seiferteric Dec 1, 2020
b291640
Add tlerr library
seiferteric Dec 1, 2020
aa90480
Add yang version info to Capabilities response extensions
seiferteric Dec 1, 2020
cba7e72
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 1, 2020
a0bc5b6
Merge branch 'azure_pr_split_bulk_support' into azure_pr_split_fix_up…
seiferteric Dec 1, 2020
73acb05
Add support for UpdatesOnly subscribe option
seiferteric Dec 2, 2020
9db7b13
Merge remote-tracking branch 'origin/master' into azure_pr_split_gnoi
seiferteric Dec 4, 2020
c2ff65d
Merge branch 'azure_pr_split_gnoi' into azure_pr_split_basic_auth
seiferteric Dec 4, 2020
20f2b5a
Merge branch 'azure_pr_split_basic_auth' into azure_pr_split_cert_auth
seiferteric Dec 4, 2020
8f5c528
Merge branch 'azure_pr_split_cert_auth' into azure_pr_split_jwt_auth
seiferteric Dec 4, 2020
596bb4f
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Dec 4, 2020
a95857e
Merge branch 'azure_pr_split_show_tech_support' into azure_pr_split_c…
seiferteric Dec 4, 2020
7a097b3
Merge branch 'azure_pr_split_copy_config' into azure_pr_split_image_mgmt
seiferteric Dec 4, 2020
134e532
Merge branch 'azure_pr_split_image_mgmt' into azure_pr_split_clear_ne…
seiferteric Dec 4, 2020
7206b13
Merge branch 'azure_pr_split_clear_neighbors' into azure_pr_split_cli…
seiferteric Dec 4, 2020
557ff84
Merge branch 'azure_pr_split_client_patches' into azure_pr_split_yang…
seiferteric Dec 4, 2020
4eb160b
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 4, 2020
2892845
Merge branch 'azure_pr_split_bulk_support' into azure_pr_split_fix_up…
seiferteric Dec 4, 2020
61ab3a6
Merge branch 'azure_pr_split_fix_update_replace' into azure_pr_split_…
seiferteric Dec 4, 2020
c666782
Remove duplicate gnoi service registration
seiferteric Dec 8, 2020
616ea83
Merge branch 'azure_pr_split_gnoi' into azure_pr_split_basic_auth
seiferteric Dec 8, 2020
cd91b58
Merge branch 'azure_pr_split_basic_auth' into azure_pr_split_cert_auth
seiferteric Dec 8, 2020
49fae07
Merge branch 'azure_pr_split_cert_auth' into azure_pr_split_jwt_auth
seiferteric Dec 8, 2020
aec0990
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Dec 8, 2020
434ca64
Merge branch 'azure_pr_split_show_tech_support' into azure_pr_split_c…
seiferteric Dec 8, 2020
6bcb5f8
Merge branch 'azure_pr_split_copy_config' into azure_pr_split_image_mgmt
seiferteric Dec 8, 2020
d327a8d
Merge branch 'azure_pr_split_image_mgmt' into azure_pr_split_clear_ne…
seiferteric Dec 8, 2020
389dbeb
Merge branch 'azure_pr_split_clear_neighbors' into azure_pr_split_cli…
seiferteric Dec 8, 2020
c11bd8d
Merge branch 'azure_pr_split_client_patches' into azure_pr_split_yang…
seiferteric Dec 8, 2020
acef348
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 8, 2020
6f7bfdd
Merge branch 'azure_pr_split_bulk_support' into azure_pr_split_fix_up…
seiferteric Dec 8, 2020
b33cffb
Merge branch 'azure_pr_split_fix_update_replace' into azure_pr_split_…
seiferteric Dec 8, 2020
04032f5
In order to support JWT Auth in read-only mode, separate out JWT RPCs…
seiferteric Dec 8, 2020
773de0f
Merge branch 'azure_pr_split_jwt_auth' into azure_pr_split_show_tech_…
seiferteric Dec 8, 2020
f31b99b
Merge branch 'azure_pr_split_show_tech_support' into azure_pr_split_c…
seiferteric Dec 8, 2020
2b0d3d4
Merge branch 'azure_pr_split_copy_config' into azure_pr_split_image_mgmt
seiferteric Dec 8, 2020
b22cccb
Merge branch 'azure_pr_split_image_mgmt' into azure_pr_split_clear_ne…
seiferteric Dec 8, 2020
4c5797c
Merge branch 'azure_pr_split_clear_neighbors' into azure_pr_split_cli…
seiferteric Dec 8, 2020
92563de
Merge branch 'azure_pr_split_client_patches' into azure_pr_split_yang…
seiferteric Dec 8, 2020
4100e6c
Merge branch 'azure_pr_split_yang_versioning' into azure_pr_split_bul…
seiferteric Dec 8, 2020
7dddc9e
Merge branch 'azure_pr_split_bulk_support' into azure_pr_split_fix_up…
seiferteric Dec 8, 2020
7e849c1
Merge branch 'azure_pr_split_fix_update_replace' into azure_pr_split_…
seiferteric Dec 8, 2020
efa378d
Address review comments, fix build issue
seiferteric Jan 9, 2021
050762e
Fix bulk bundle version check
seiferteric Jan 9, 2021
851362e
Merge remote-tracking branch 'origin/master' into azure_pr_split_upda…
seiferteric Jan 9, 2021
8963ef0
Add unit tests for new features
seiferteric Jan 11, 2021
8fc49d2
Add error message to audit log
seiferteric Jan 12, 2021
689cd60
Change defaults for auth and client cert back
seiferteric Jan 14, 2021
177b689
Fix missing jwt mode in client_auth options
seiferteric Jan 14, 2021
2e777d5
Enable default auth modes only in read/write mode
seiferteric Jan 15, 2021
b9361eb
Merge remote-tracking branch 'origin/master' into azure_pr_split_upda…
seiferteric Feb 4, 2021
3e68cbb
Fix merge build issue
seiferteric Feb 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ go.mod:
$(GO_DEPS): go.mod $(PATCHES)
# FIXME temporary workaround for crypto not downloading..
$(GO) get golang.org/x/crypto/ssh/terminal@e9b2fee46413
$(GO) get github.com/jipanyang/gnxi@v0.0.0-20181221084354-f0a90cca6fd0
$(GO) mod vendor
$(MGMT_COMMON_DIR)/patches/apply.sh vendor
cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413 vendor/golang.org/x/crypto
cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20191206172530-e9b2fee46413/* vendor/golang.org/x/crypto/
mkdir -p vendor/github.com/jipanyang/gnxi/
cp -r $(GOPATH)/pkg/mod/github.com/jipanyang/gnxi@v0.0.0-20181221084354-f0a90cca6fd0/* vendor/github.com/jipanyang/gnxi/
chmod -R u+w vendor
patch -d vendor -p0 <patches/gnmi_cli.all.patch
patch -d vendor -p0 < patches/gnmi_cli.all.patch
patch -d vendor -p0 < patches/gnmi_set.patch
patch -d vendor -p0 < patches/gnmi_get.patch
touch $@

go-deps: $(GO_DEPS)
Expand All @@ -47,9 +52,10 @@ go-deps-clean:
sonic-telemetry: $(GO_DEPS)
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/Azure/sonic-telemetry/telemetry
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/Azure/sonic-telemetry/dialout/dialout_client_cli
$(GO) install github.com/jipanyang/gnxi/gnmi_get
$(GO) install github.com/jipanyang/gnxi/gnmi_set
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) install -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
$(GO) install -mod=vendor github.com/Azure/sonic-telemetry/gnoi_client

check:
sudo mkdir -p ${DBDIR}
Expand All @@ -74,12 +80,14 @@ install:
$(INSTALL) -D $(BUILD_DIR)/gnmi_get $(DESTDIR)/usr/sbin/gnmi_get
$(INSTALL) -D $(BUILD_DIR)/gnmi_set $(DESTDIR)/usr/sbin/gnmi_set
$(INSTALL) -D $(BUILD_DIR)/gnmi_cli $(DESTDIR)/usr/sbin/gnmi_cli
$(INSTALL) -D $(BUILD_DIR)/gnoi_client $(DESTDIR)/usr/sbin/gnoi_client


deinstall:
rm $(DESTDIR)/usr/sbin/telemetry
rm $(DESTDIR)/usr/sbin/dialout_client_cli
rm $(DESTDIR)/usr/sbin/gnmi_get
rm $(DESTDIR)/usr/sbin/gnmi_set
rm $(DESTDIR)/usr/sbin/gnoi_client


63 changes: 63 additions & 0 deletions common_utils/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package common_utils

import (
"context"
"fmt"
"sync/atomic"
)


// AuthInfo holds data about the authenticated user
type AuthInfo struct {
// Username
User string
AuthEnabled bool
// Roles
Roles []string
}

// RequestContext holds metadata about REST request.
type RequestContext struct {

// Unique reqiest id
ID string

// Auth contains the authorized user information
Auth AuthInfo

//Bundle Version is the release yang models version.
BundleVersion *string
}

type contextkey int

const requestContextKey contextkey = 0

// Request Id generator
var requestCounter uint64

// GetContext function returns the RequestContext object for a
// HTTP request. RequestContext is maintained as a context value of
seiferteric marked this conversation as resolved.
Show resolved Hide resolved
// the request. Creates a new RequestContext object is not already
// available; in which case this function also creates a copy of
// the HTTP request object with new context.
func GetContext(ctx context.Context) (*RequestContext, context.Context) {
cv := ctx.Value(requestContextKey)
if cv != nil {
return cv.(*RequestContext), ctx
}

rc := new(RequestContext)
rc.ID = fmt.Sprintf("TELEMETRY-%v", atomic.AddUint64(&requestCounter, 1))

ctx = context.WithValue(ctx, requestContextKey, rc)
return rc, ctx
}

func GetUsername(ctx context.Context, username *string) {
rc, ctx := GetContext(ctx)
if rc != nil {
*username = rc.Auth.User
}
}

42 changes: 42 additions & 0 deletions gnmi_server/basicAuth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gnmi

import (
"github.com/Azure/sonic-telemetry/common_utils"
"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)

func BasicAuthenAndAuthor(ctx context.Context) (context.Context, error) {
rc, ctx := common_utils.GetContext(ctx)
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return ctx, status.Errorf(codes.Unknown, "Invalid context")
}

var username string
var passwd string
if username_a, ok := md["username"]; ok {
username = username_a[0]
} else {
return ctx, status.Errorf(codes.Unauthenticated, "No Username Provided")
}

if passwd_a, ok := md["password"]; ok {
passwd = passwd_a[0]
} else {
return ctx, status.Errorf(codes.Unauthenticated, "No Password Provided")
}
if err := PopulateAuthStruct(username, &rc.Auth, nil); err != nil {
glog.Infof("[%s] Failed to retrieve authentication information; %v", rc.ID, err)
return ctx, status.Errorf(codes.Unauthenticated, "")
}
auth_success, _ := UserPwAuth(username, passwd)
if auth_success == false {
return ctx, status.Errorf(codes.PermissionDenied, "Invalid Password")
}

return ctx, nil
}
41 changes: 41 additions & 0 deletions gnmi_server/clientCertAuth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gnmi

import (
"github.com/Azure/sonic-telemetry/common_utils"
"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
)

func ClientCertAuthenAndAuthor(ctx context.Context) (context.Context, error) {
rc, ctx := common_utils.GetContext(ctx)
p, ok := peer.FromContext(ctx)
if !ok {
return ctx, status.Error(codes.Unauthenticated, "no peer found")
}
tlsAuth, ok := p.AuthInfo.(credentials.TLSInfo)
if !ok {
return ctx, status.Error(codes.Unauthenticated, "unexpected peer transport credentials")
}
if len(tlsAuth.State.VerifiedChains) == 0 || len(tlsAuth.State.VerifiedChains[0]) == 0 {
return ctx, status.Error(codes.Unauthenticated, "could not verify peer certificate")
}

var username string

username = tlsAuth.State.VerifiedChains[0][0].Subject.CommonName

if len(username) == 0 {
return ctx, status.Error(codes.Unauthenticated, "invalid username in certificate common name.")
}

if err := PopulateAuthStruct(username, &rc.Auth, nil); err != nil {
glog.Infof("[%s] Failed to retrieve authentication information; %v", rc.ID, err)
return ctx, status.Errorf(codes.Unauthenticated, "")
}

return ctx, nil
}
9 changes: 6 additions & 3 deletions gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *Client) populateDbPathSubscrition(sublist *gnmipb.SubscriptionList) ([]
// internally after sync until a Poll request is made to the server.
func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
defer log.V(1).Infof("Client %s shutdown", c)
ctx := stream.Context()

if stream == nil {
return grpc.Errorf(codes.FailedPrecondition, "cannot start client: stream is nil")
Expand All @@ -96,6 +97,8 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
log.V(2).Infof("Client %s recieved initial query %v", c, query)

c.subscribe = query.GetSubscribe()
extensions := query.GetExtension()

if c.subscribe == nil {
return grpc.Errorf(codes.InvalidArgument, "first message must be SubscriptionList: %q", query)
}
Expand Down Expand Up @@ -124,7 +127,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
dc, err = sdc.NewDbClient(paths, prefix)
} else {
/* For any other target or no target create new Transl Client. */
dc, err = sdc.NewTranslClient(prefix, paths)
dc, err = sdc.NewTranslClient(prefix, paths, ctx, extensions)
}

if err != nil {
Expand All @@ -140,12 +143,12 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
c.polled = make(chan struct{}, 1)
c.polled <- struct{}{}
c.w.Add(1)
go dc.PollRun(c.q, c.polled, &c.w)
go dc.PollRun(c.q, c.polled, &c.w, c.subscribe)
case gnmipb.SubscriptionList_ONCE:
c.once = make(chan struct{}, 1)
c.once <- struct{}{}
c.w.Add(1)
go dc.OnceRun(c.q, c.once, &c.w)
go dc.OnceRun(c.q, c.once, &c.w, c.subscribe)
default:
return grpc.Errorf(codes.InvalidArgument, "Unkown subscription mode: %q", query)
}
Expand Down
Loading