Commit Graph

41 Commits

Author SHA1 Message Date
Francesco Giudici fda53de0e2
Kubebuilder: fix MachineRegistration search during registration (#280)
* operator: fix MachineSelector controller log

* operator: fix MachineRegistration search in registration

Fixes #279

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-12-02 16:13:34 +01:00
Francesco Giudici 8c1e1df563
[controller_runtime] add registration protocol version (#266)
Fixes: #265 

* registration: negotiate registration protocol

* operator: always update the MachineInventory for authenticated clients

* register: rename sendData to sendSMBIOSdata

* register: rework the Register() function

* operator: rework the registration protocol loop

* operator: no need to return the msgType from the registration loop

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-11-29 18:08:15 +01:00
Francesco Giudici 5df274078b
[controller_runtime] operator/registration: switch to Kubebuilder client (#256)
* operator/registration: switch to Kubebuilder client

Fixes #239

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator/registration: adapt tests to Kubebuilder client

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* unit-tests: vendor controller-runtime fake client

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator: add yaml annotations for correct marshalling

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator/RBAC: add "get" verb to ServiceAccount resources

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator: generate rbac

make generate-manifests
make build-rbac

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* Add elementalcli package

Create a separate package to deal with elemental-cli installation.
This brings the elemental-cli functions declared in the config package
to a new package that just parses a map[string]interface argument.

This is a step to enable usage of the elemental-cli functions with the
new elementalv1.Config.Elemental.Install type.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* register: switch to Kubebuilder api

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* register: add mapstructure annotations for correct marshalling

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* register: reduce complexity of the run function

Make linter happy:
"cyclomatic complexity 16 of func `run` is high (> 15) (gocyclo)"

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* register: drop io/ioutil in favor of os package

io/ioutil is deprecated

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-11-28 17:34:47 +01:00
Francesco Giudici d466e048a7
operator: unit-tests: add coverage for unauthenticatedResponse() (#217)
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-20 08:55:42 +02:00
Francesco Giudici 937d35b527
Elemental Operator: manage empty config in MachineRegistrations (#213)
* operator: manage empty config in MachineRegistrations

We don't deal with empty Spec:Config in MachineRegistrations: in that
case we would end up with a nil Config structure, which we don't check
causing the operator to panic.

Just check and deal with empty (nil) MachineRegistration config.

Fixes #202

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator:trivial: rename var machineRegistration to registration

In order to manage a MachineRegistration resource we instantiate a var named
'registration' in all the functions of the server package,  but in the
'unauthenticatedResponse' function.
Let's stay coherent: rename the variable.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator: tests: expand the data structure TestInitNewInventory

This has no functional change: just extend the configuration parameter
that can be set in the data structure used for the tests.
Make use of it in the following commit.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* operator: tests: check empty config in MachineRegistrations

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-10-18 14:52:36 +02:00
Francesco Giudici deef7657b6 operator: return error when the ServiceAccount has no secrets
We need to lend the secret to the rancher-system-agent: without that
let's not even start the elemental deployment.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-23 15:29:07 +02:00
Itxaka 4fab515a30
Rework client to accept a ClientInterface (#166) 2022-09-07 10:39:26 +02:00
Francesco Giudici 5da3ac15ff register/operator: drop MachineInventory labels passed from the client
The right way to set labels for the MachineInventory objs is to set
them in the MachineRegistration:spec:machineInventoryLabels, which
will be processed by the operator.
Drop MachineRegistration spec:config:elemental:registration:labels.

Fixes #161

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-06 09:24:14 +02:00
Francesco Giudici 01afffd0e2 unit-tests: check default machine name
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-05 10:59:18 +02:00
Francesco Giudici 41b89ee1ed operator: change default MachineInventory name
right now when the MachineRegistration is missing a 'spec.MachineName'
value we set the following hostname:
m-${System Information/Manufacturer}-${System Information/Product Name}-${System Information/UUID}

This causes an invalid hostname if config.registration.no-smbios is set
to true, failing the registration.
When no-smbios is set to false instead, we may still fail the registration
as the hostname derived by no-smbios data is truncated to 58 chars, which
may end up truncating the UUID, which is the only parameter ensuring uniqueness.

This PR changes the default MachineInventory name to a UUID prepended by "m-":
the UUID is taken from "${System Information/UUID}" when SMBIOS data is available,
otherwise the UUID is randomly generated.

Fixes: https://github.com/rancher/elemental-operator/issues/144

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-05 10:59:18 +02:00
Itxaka 3d28c5d855
Configure custom smbios data (#157) 2022-09-02 14:15:22 +02:00
Francesco Giudici 64f470348a operator: ensure inventory.Labels is not nil before adding labels
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-02 10:05:45 +02:00
Itxaka 75792d6d8d
Add extra labels with smbios data (#155) 2022-09-01 18:15:14 +02:00
Francesco Giudici 0ffcfe8e83 operator: add unit-test for mergeInventoryLabels()
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-01 16:25:59 +02:00
Francesco Giudici fa5f689e20 operator/register: drop unused code
remove old code passing data via HTTP labels

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-01 16:25:59 +02:00
Francesco Giudici d49adeb7ed operator/register: rework the registration protocol
This commit changes the communication protocol between the operator and
the elemental-register client in order to take full advantage of the websocket
connection: SMBIOS data and labels are now passed via the websocket channel.
The protocol is now extensible and could be easily extended to pass arbitrary
data or request different kind of services to the operator.

This commit breaks backwards compatibility with older operators and
elemental-register clients.

Fixes #5

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-01 16:25:59 +02:00
Francesco Giudici 2bcc2ffff6 register: set a timeout for retrieving the installation config
We already had a deadline on the operator side: add to the
registering client to.
Share websocket configuration options as we will soon need it
for establishing a common protocol.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-09-01 16:25:59 +02:00
Francesco Giudici 52410aa3b3 fix linter: cyclomatic complexity of ServeHTTP is 16
Error: cyclomatic complexity 16 of func `(*InventoryServer).ServeHTTP` is high (> 15) (gocyclo)

Move code to update labels from headers to subfunction

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-08-31 15:31:03 +02:00
Francesco Giudici 2b646ff145 operator: move websocket management logic out of the tpm package
Till now the TPM package was in charge to upgrade the HTTP connection
and manage the websocket one.
Move the connection management to the server package to split connection
management from TPM authentication.
This will allow us later to pass the smbios data and the labels through
the channel instead of abusing HTTP headers.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-08-31 15:31:03 +02:00
Francesco Giudici 7192507964 minor: drop duplicated logging
we already log the same error in the calling function
(writeMachineInventoryCloudConfig)

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-08-31 15:31:03 +02:00
Itxaka 72971ff776
Backwards compatibility for smbios headers (#137) 2022-08-12 11:14:34 +02:00
Itxaka f170a1aa62
Split header into 7Kb of data (#133)
This generates several X-Cattle-Smbios-NUMER headers when sending the
data to the operator in order to limit the max size of each individual
header to 7Kb. By default nginx is configured with a max of 8Kb header
and will return a 400 error if the headers excess that size.

As we currently use a GET+Websocket to go trougth the challenge/response
of TPM, this is the easiest implementation to workaround the issue.

Signed-off-by: Itxaka <igarcia@suse.com>

Signed-off-by: Itxaka <igarcia@suse.com>
2022-08-11 14:46:04 +02:00
Francesco Giudici 5f07c444e3 operator: pass all the registration fields on unauthenticated query
Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-08-01 15:42:12 +02:00
Francesco Giudici 2d5fde7da0 operator: drop duplicated MachineInventory init code
Labels and Annotations are initialized the same way in
createMachineInventory()

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-08-01 10:37:49 +02:00
Francesco Giudici b5c35b9d38 operator: fix adding machineInventoryLabels after initial registration
2022/07/27 19:44:52 http: panic serving pipe: assignment to entry in nil map
goroutine 1585 [running]:
net/http.(*conn).serve.func1()
        /usr/local/go/src/net/http/server.go:1802 +0xb9
panic({0x1b1a3e0, 0x20359e0})
        /usr/local/go/src/runtime/panic.go:1047 +0x266
github.com/rancher/elemental-operator/pkg/server.(*InventoryServer).ServeHTTP(0xc0016cd100, {0x2071e70, 0xc000988000}, 0x2032db8)
        /src/pkg/server/register.go:88 +0x55e
github.com/rancher/steve/pkg/auth.ToMiddleware.func1.1({0x2071e70, 0xc000988000}, 0xc00063d300)
        /go/pkg/mod/github.com/rancher/steve@v0.0.0-20220503004032-53511a06ff37/pkg/auth/filter.go:167 +0x3d4
net/http.HandlerFunc.ServeHTTP(0x0, {0x2071e70, 0xc000988000}, 0x464b8e)
        /usr/local/go/src/net/http/server.go:2047 +0x2f
net/http.serverHandler.ServeHTTP({0xc002732630}, {0x2071e70, 0xc000988000}, 0xc00063d300)
        /usr/local/go/src/net/http/server.go:2879 +0x43b
net/http.(*conn).serve(0xc0009280a0, {0x207a700, 0xc001d59440})
        /usr/local/go/src/net/http/server.go:1930 +0xb08
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:3034 +0x4e8

Fixes: #92

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-07-28 10:31:37 +02:00
David Cassany Viladomat dd7a4ac258
Do note fetch cloud-config on unauthenticated registartion calls (#67)
Signed-off-by: David Cassany <dcassany@suse.com>
2022-07-20 18:22:15 +02:00
Francesco Giudici f655a80342 Change the default machine name to include the UUID
The current default machine name is made up from SMSBIOS:
- Manufacturer
- Product Name
- Serial Number
for VMs from QEMU anyway the Serial Number is not set, loosing uniqueness for
the machine names (e.g., m-qemu-standard-pc-q35-ich9-2009-not-specified).

Switch the Serial Number to UUID, so that we will have by default unique machine
names also for QEMU VMs.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
2022-07-20 15:45:21 +02:00
David Cassany Viladomat 79d957e1df
Adds support for cloud-config data in machine registration (#61)
Signed-off-by: David Cassany <dcassany@suse.com>
2022-07-20 10:42:08 +02:00
Itxaka 278b9b2c39
Return a Config.Config in MachineInventory (#35) 2022-07-13 16:28:48 +02:00
Itxaka e87eb80c9c
Use cacert from rancher and use serverl-url from rancher (#36)
* Generate v3.Setting code

Signed-off-by: Itxaka <igarcia@suse.com>

* Use the rancher cacerts for the registration

Also drops the cacert passing via chart, adds proper permissions to the
settings resource, adds the cache index and checks that indeed we are
returning a cacert on the registration url

Signed-off-by: Itxaka <igarcia@suse.com>

* fix lint

Signed-off-by: Itxaka <igarcia@suse.com>

* Drop manual rancherl-url and get the rancher url automatically

Drop any manual setup of rancher-url and use the settings to get the set
rancher-url

Signed-off-by: Itxaka <igarcia@suse.com>

* Small fix for getRancherCACert

Signed-off-by: Itxaka <igarcia@suse.com>

* Fix test setting the wrong url

Signed-off-by: Itxaka <igarcia@suse.com>
2022-07-13 16:11:21 +02:00
David Cassany Viladomat 14d4d957cf
Share installation configuration structures (#24)
This commit makes sure elemental-operator and elemental-installer are
using the same structures to describe and define the elemental-cli
installation.

Signed-off-by: David Cassany <dcassany@suse.com>
2022-07-12 12:36:53 +02:00
Itxaka 5c5f1150cb Fix all the test, remove leftovers from transition
Remove all the mentions to rancheros-operator in tests, imports and
dependencies.

Restore e2e scripts and test targets on makefile

Fix all lint issues

Signed-off-by: Itxaka <igarcia@suse.com>
2022-07-11 15:12:19 +02:00
Jacob Payne c5a5dbd77f renamed to elemental-operator and switched to system agent 2022-06-30 16:01:13 +00:00
Itxaka 26684d1888 Drop everything not needed for ros-operator
- Drops everything not needed for ros-operator
 - New simple Dockerfile
 - New jobs based on ros-operator only
 - Remove uneeded tests
 - Remove dependency on os2 images for integration tests
 - Use gorelease to release ros-operator binaries
 - Use docker to push ci images to ros-operator-ci registry on PR
 - Use docker to push master/tag images to ros-operator registry
 - Build chart indepently
 - Have a null test CI job for future integration tests

Signed-off-by: Itxaka <igarcia@suse.com>
2022-03-24 09:47:18 +01:00
Itxaka 9fed2edefc
Rework golangci-lint config and github CI (#34) 2022-03-03 09:16:03 +01:00
Ettore Di Giacinto 20f07ba9db Attach rancher ca-cert to sample cloud-init from ros-operator
Fixes: https://github.com/rancher-sandbox/os2/issues/1
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
2022-03-01 17:15:48 +01:00
Ettore Di Giacinto 97d58074ee
Refactor import paths
See: https://github.com/rancher-sandbox/cOS-toolkit/issues/1105

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
2022-01-28 14:00:29 +01:00
Darren Shepherd 7876d148e4 Fix SUC upgrade and PXE+registrationURL 2021-12-01 10:10:35 -07:00
Darren Shepherd 901973e5f6 Add TPM and MachineRegister support 2021-10-29 23:08:26 -07:00
Darren Shepherd 4085b2977b Rename to rancher/os2 2021-10-20 12:19:44 -07:00
Darren Shepherd 5675644d9f Add operator 2021-10-20 10:58:54 -07:00