feat(openconfig): Implement ManagementAccess provider - #485
Conversation
Add EnsureManagementAccess and DeleteManagementAccess to the OpenConfig provider using openconfig-system YANG paths: - gRPC server: /system/grpc-servers/grpc-server[name=gnmi]/config - SSH server: /system/ssh-server/config Unsupported fields (spec.grpc.gnmi, spec.ssh.sessionLimit) are rejected with a terminal UnsupportedFieldError, following the DNS provider pattern. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Robert Gildein <rgildein@users.noreply.github.com>
| Timeout uint32 `json:"timeout,omitempty"` | ||
| } | ||
|
|
||
| func (s *SSHServer) XPath() string { |
There was a problem hiding this comment.
| func (s *SSHServer) XPath() string { | |
| func (*SSHServer) XPath() string { |
in such cases, we can omit the receiver variable name
Signed-off-by: Robert Gildein <rgildein@users.noreply.github.com>
|
|
||
| var _ provider.ManagementAccessProvider = (*Provider)(nil) | ||
|
|
||
| const grpcServerName = "gnmi" |
There was a problem hiding this comment.
I don't think this is a universal standard that is set by openconfig. As such, do we want to hardcode this name here, or should we rather allow to set this name from the spec? On a provider such as cisco nx-os which doesn't support multiple servers, this field could then perhaps be ignored?
There was a problem hiding this comment.
I was trying to follow what we have for NX-OS, where we do not set the name. My assumptions was that there is only one resource kind: ManagementAccess per device, so setting generic name (maybe we can go with even something like 'network-operator-gnmi'). Is that true or it's excepted to have multiple resources?
If you think it will be useful, we can do as you say add this to the spec and ignore it for Cisco provider. BTW, I think that Cisco support multiple servers, but without names.
There was a problem hiding this comment.
I think we'll only have one kind: ManagementAccess resource per Device. However, I think some device platforms (like Nokia SRLinux) can have multiple named grpc servers. On Cisco NX-OS I'm only aware that there is a single grpc server without a name. Where did you read that Cisco NX-OS supports multiple grpc servers?
There was a problem hiding this comment.
Here, it's not specifically mentioned how, but that two server can used.
Anyway, I think it makes sense to add name to the spec and raise error if it's used with Cisco provider.
Adds a ServerName field to the GRPC spec, used by the OpenConfig provider to identify the gRPC server instance on the device (defaults to "gnmi"). Raises UnsupportedFieldError on Cisco NX-OS where the name is not configurable. Also adds DeleteManagementAccessRequest to carry spec context into deletion. Co-authored-by: Claude <claude@anthropic.com> Signed-off-by: Robert Gildein <rgildein@users.noreply.github.com>
Signed-off-by: Robert Gildein <rgildein@users.noreply.github.com>
Merging this branch changes the coverage (1 decrease, 1 increase)
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
| // +optional | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=63 | ||
| ServerName string `json:"serverName,omitempty"` |
There was a problem hiding this comment.
I think we need to make this Immutable once set.
The reasoning is that otherwise we can leave orphaned config on a device which we want to avoid. Assume you create a ManagementAccess resource with a grpc server and name "foo" and it creates a server named like that. Now you change the spec to have the grpc server named "bar". What will happen now is that it will again create a new grpc server, with a different name, and leave the previous gprc server running and untouched. This is because the server name is part of the YANG path, as such it identifies the tree which is updated. If it can change, then we might end up creating/updating an entirely different path.
There was a problem hiding this comment.
Good point, I did not know that and did not realised that we can do that. It's not possible to do "update" for the name? If server exists we will rename it? I think it's better to be immutable, since it make more sense for user to create new resource rather that edit existing one, but I'm curious if "update" is possible.
There was a problem hiding this comment.
It's not possible to do "update" for the name? If server exists we will rename it?
So a rename in the yang model would actually be to delete the old element, e.g. openconfig-system:system/grpc-servers/grpc-server[name=foo], and create a new one, e.g openconfig-system:system/grpc-servers/grpc-server[name=bar]. As the name field of the object is part of the path, so there is no way of doing something like an update to e.g. openconfig-system:system/grpc-servers/grpc-server[name=foo] with {"name":"bar"}. XPath and object field (name in this case) always match.
Now based on this, there is no easy way for us to know, that an existing openconfig-system:system/grpc-servers/grpc-server[name=foo] on the device was our operator in a previous reconcilation run. You just get the current kubernetes resource (now having .spec.name=bar).
In order to actually perform the deletion of the previous element, you would need knowledge over a previous kubernetes resource version, that was successfully configured, before being changed by a user to the now current version. 😄
Description
Add EnsureManagementAccess and DeleteManagementAccess to the OpenConfig provider using openconfig-system YANG paths:
Unsupported fields (spec.grpc.gnmi, spec.ssh.sessionLimit) are rejected with a terminal UnsupportedFieldError, following the DNS provider pattern.
Adds a configurable
spec.grpc.serverNamefield — defaults to"gnmi"on OpenConfig devices viacmp.Or. RaisesUnsupportedFieldErroron Cisco NX-OS where the server name is not configurable. Also introducesDeleteManagementAccessRequestto carry spec context (includingserverName) into deletion.My prompt
Claude plan
Plan: Add ManagementAccess to OpenConfig Provider
Context
The
ManagementAccessCRD manages gRPC/gNMI and SSH server access on network devices. The NX-OS provider already implementsEnsureManagementAccessandDeleteManagementAccess, but the OpenConfig provider does not. The controller already checks if a provider implementsManagementAccessProvider(defined ininternal/provider/provider.go) and sets aNotImplementedReasonstatus when it doesn't. This task wires up the OpenConfig provider to configure devices using standard OpenConfig YANG paths fromopenconfig-system-grpcandopenconfig-system.OpenConfig YANG Paths
gRPC server (named list, key:
name):SSH server (singleton container):
Implementation
New file:
internal/provider/openconfig/managementaccess.goCompile-time assertion:
Two structs implementing
gnmiext.DataElement:GRPCServer— targets the grpc-server list item:openconfig-system:system/grpc-servers/grpc-server[name=<serverName>]/configenable,port,certificate-id(omitempty),network-instance(omitempty)spec.grpc.*SSHServer— targets the SSH server config container:openconfig-system:system/ssh-server/configenable,timeout(seconds, uint32)spec.ssh.*Claude Test results
Applied spec:
Manual test result