Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ PROTOC_OPTS_WITHOUT_VENDOR := -I/usr/local/include -I/usr/include
# Generate following go & grpc bindings using teh legacy protoc-gen-go
PROTO_GO_BINDINGS += proto/sonic_internal.pb.go
PROTO_GO_BINDINGS += proto/gnoi/sonic_debug.pb.go
PROTO_GO_BINDINGS += proto/gnoi/oras/oras.pb.go

$(BUILD_GNOI_YANG_PROTO_DIR)/.proto_api_done: $(API_YANGS)
@echo "+++++ Generating PROTOBUF files for API Yang modules; +++++"
Expand Down
387 changes: 387 additions & 0 deletions doc/oras-pull-design.md

Large diffs are not rendered by default.

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

import (
log "github.com/golang/glog"

gnoioras "github.com/sonic-net/sonic-gnmi/pkg/gnoi/oras"
gnoi_oras_pb "github.com/sonic-net/sonic-gnmi/proto/gnoi/oras"
)

// Pull is the entry point for the SONiC ORAS Pull RPC. Authentication is
// applied the same way as the other gNOI services on this server; the actual
// pull logic lives in pkg/gnoi/oras.
func (srv *OrasServer) Pull(req *gnoi_oras_pb.PullRequest, stream gnoi_oras_pb.Oras_PullServer) error {
log.Infof("GNOI Oras Pull RPC called with registry=%s repository=%s ref=%s",
req.GetRegistry(), req.GetRepository(), pullRefDescription(req))
if _, err := authenticate(srv.config, stream.Context(), "gnoi", true); err != nil {
log.Errorf("authentication failed in Oras.Pull RPC: %v", err)
return err
}
return gnoioras.HandlePull(req, stream)
}

func pullRefDescription(req *gnoi_oras_pb.PullRequest) string {
if d := req.GetDigest(); d != "" {
return d
}
return req.GetTag()
}
18 changes: 15 additions & 3 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
gnoi_os_pb "github.com/openconfig/gnoi/os"
gnoi_debug "github.com/sonic-net/sonic-gnmi/pkg/gnoi/debug"
gnoi_debug_pb "github.com/sonic-net/sonic-gnmi/proto/gnoi/debug"
gnoi_oras_pb "github.com/sonic-net/sonic-gnmi/proto/gnoi/oras"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -165,6 +166,12 @@ type HealthzServer struct {
gnoi_healthz_pb.UnimplementedHealthzServer
}

// OrasServer is the server API for the SONiC ORAS Pull service.
type OrasServer struct {
*Server
gnoi_oras_pb.UnimplementedOrasServer
}

type AuthTypes map[string]bool

// Config is a collection of values for Server
Expand Down Expand Up @@ -278,7 +285,7 @@ func (i AuthTypes) Unset(mode string) error {
// registerAllServices registers all gNMI and gNOI services on the given gRPC server.
func registerAllServices(s *grpc.Server, srv *Server, fileSrv *FileServer,
osSrv *OSServer, containerzSrv *ContainerzServer,
debugSrv *DebugServer, healthzSrv *HealthzServer) {
debugSrv *DebugServer, healthzSrv *HealthzServer, orasSrv *OrasServer) {
gnmipb.RegisterGNMIServer(s, srv)
factory_reset.RegisterFactoryResetServer(s, srv)
spb_jwt_gnoi.RegisterSonicJwtServiceServer(s, srv)
Expand All @@ -290,6 +297,10 @@ func registerAllServices(s *grpc.Server, srv *Server, fileSrv *FileServer,
gnoi_debug_pb.RegisterDebugServer(s, debugSrv)
gnoi_healthz_pb.RegisterHealthzServer(s, healthzSrv)
}
// ORAS Pull writes only into an allowlisted staging area inside the
// container; it has no relation to the gNMI write paths, so it is not
// gated by EnableTranslibWrite/EnableNativeWrite.
gnoi_oras_pb.RegisterOrasServer(s, orasSrv)
if srv.config.EnableTranslibWrite {
spb_gnoi.RegisterSonicServiceServer(s, srv)
}
Expand Down Expand Up @@ -333,6 +344,7 @@ func NewServer(config *Config, tlsOpts []grpc.ServerOption, commonOpts []grpc.Se
readWhitelist: readWhitelist,
writeWhitelist: writeWhitelist,
}
orasSrv := &OrasServer{Server: srv}

var err error

Expand All @@ -347,7 +359,7 @@ func NewServer(config *Config, tlsOpts []grpc.ServerOption, commonOpts []grpc.Se
return nil, fmt.Errorf("failed to open listener port %d: %v", config.Port, err)
}

registerAllServices(srv.s, srv, fileSrv, osSrv, containerzSrv, debugSrv, healthzSrv)
registerAllServices(srv.s, srv, fileSrv, osSrv, containerzSrv, debugSrv, healthzSrv, orasSrv)
}

// UDS Server (UnixSocket set)
Expand Down Expand Up @@ -383,7 +395,7 @@ func NewServer(config *Config, tlsOpts []grpc.ServerOption, commonOpts []grpc.Se
srv.udsListener = nil
srv.udsServer = nil
} else {
registerAllServices(srv.udsServer, srv, fileSrv, osSrv, containerzSrv, debugSrv, healthzSrv)
registerAllServices(srv.udsServer, srv, fileSrv, osSrv, containerzSrv, debugSrv, healthzSrv, orasSrv)
}
}

Expand Down
16 changes: 11 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module github.com/sonic-net/sonic-gnmi

go 1.21
go 1.23.0

toolchain go1.23.8

require (
github.com/Azure/sonic-mgmt-common v0.0.0-00010101000000-000000000000
github.com/Workiva/go-datastructures v1.0.50
github.com/agiledragon/gomonkey/v2 v2.8.0
github.com/alicebob/miniredis/v2 v2.35.0
github.com/c9s/goprocinfo v0.0.0-20191125144613-4acdd056c72d
github.com/dgrijalva/jwt-go v3.2.1-0.20210802184156-9742bd7fca1c+incompatible
github.com/fsnotify/fsnotify v1.4.7
Expand All @@ -18,21 +21,26 @@ require (
github.com/google/gnxi v0.0.0-20181220173256-89f51f0ce1e2
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/kylelemons/godebug v1.1.0
github.com/maruel/natural v1.1.1
github.com/msteinert/pam v0.0.0-20201130170657-e61372126161
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802
github.com/openconfig/gnoi v0.3.0
github.com/openconfig/ygot v0.7.1
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.1
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.24.0
golang.org/x/net v0.26.0
google.golang.org/grpc v1.64.1
google.golang.org/grpc/security/advancedtls v1.0.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v2 v2.2.8
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/sh/v3 v3.8.0
oras.land/oras-go/v2 v2.6.0
)

require (
github.com/alicebob/miniredis/v2 v2.35.0 // indirect
github.com/antchfx/jsonquery v1.1.4 // indirect
github.com/antchfx/xmlquery v1.3.1 // indirect
github.com/antchfx/xpath v1.1.10 // indirect
Expand All @@ -42,7 +50,6 @@ require (
github.com/go-redis/redis/v7 v7.0.0-beta.3.0.20190824101152-d19aba07b476 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/maruel/natural v1.1.1 // indirect
github.com/onsi/ginkgo v1.10.3 // indirect
github.com/onsi/gomega v1.7.1 // indirect
github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc // indirect
Expand All @@ -51,12 +58,11 @@ require (
github.com/yuin/gopher-lua v1.1.1 // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect
mvdan.cc/sh/v3 v3.8.0 // indirect
)

replace (
Expand Down
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0+
github.com/envoyproxy/protoc-gen-validate v0.10.1/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -833,8 +835,9 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -871,6 +874,10 @@ github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc/go.mod h1:dhXaV0
github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
github.com/openconfig/ygot v0.7.1 h1:kqDRYQpowXTr7EhGwr2BBDKJzqs+H8aFYjffYQ8lBsw=
github.com/openconfig/ygot v0.7.1/go.mod h1:5MwNX6DMP1QMf2eQjW+aJN/KNslVqRJtbfSL3SO6Urk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f h1:WyCn68lTiytVSkk7W1K9nBiSGTSRlUOdyTnSjwrIlok=
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f/go.mod h1:/iRjX3DdSK956SzsUdV55J+wIsQ+2IBWmBrB4RvZfk4=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
Expand All @@ -891,9 +898,9 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down Expand Up @@ -1116,6 +1123,8 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -1653,6 +1662,8 @@ modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/z v1.5.1/go.mod h1:eWFB510QWW5Th9YGZT81s+LwvaAs3Q2yr4sP0rmLkv8=
mvdan.cc/sh/v3 v3.8.0 h1:ZxuJipLZwr/HLbASonmXtcvvC9HXY9d2lXZHnKGjFc8=
mvdan.cc/sh/v3 v3.8.0/go.mod h1:w04623xkgBVo7/IUK89E0g8hBykgEpN0vgOj3RJr6MY=
oras.land/oras-go/v2 v2.6.0 h1:X4ELRsiGkrbeox69+9tzTu492FMUu7zJQW6eJU+I2oc=
oras.land/oras-go/v2 v2.6.0/go.mod h1:magiQDfG6H1O9APp+rOsvCPcW1GD2MM7vgnKY0Y+u1o=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
10 changes: 10 additions & 0 deletions pkg/gnoi/oras/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package oras

import "encoding/json"

// parseManifest decodes an OCI image manifest. Lenient on unknown fields:
// oras-go writes annotations we don't care about, and rejecting unknown
// fields would also break against forward-compatible spec changes.
func parseManifest(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
Loading
Loading