Skip to content

feat: log and store redacted machine config diffs #1305

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

Merged
Merged
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
343 changes: 195 additions & 148 deletions client/api/omni/specs/omni.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions client/api/omni/specs/omni.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1356,3 +1356,7 @@ message InfraProviderCombinedStatusSpec {

Health health = 4;
}

message MachineConfigDiffSpec {
string diff = 1;
}
173 changes: 173 additions & 0 deletions client/api/omni/specs/omni_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions client/pkg/omni/resources/omni/machine_config_diff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package omni

import (
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
"github.com/cosi-project/runtime/pkg/resource/protobuf"
"github.com/cosi-project/runtime/pkg/resource/typed"

"github.com/siderolabs/omni/client/api/omni/specs"
"github.com/siderolabs/omni/client/pkg/omni/resources"
)

// NewMachineConfigDiff creates a new MachineConfigDiff resource.
func NewMachineConfigDiff(id resource.ID) *MachineConfigDiff {
return typed.NewResource[MachineConfigDiffSpec, MachineConfigDiffExtension](
resource.NewMetadata(resources.DefaultNamespace, MachineConfigDiffType, id, resource.VersionUndefined),
protobuf.NewResourceSpec(&specs.MachineConfigDiffSpec{}),
)
}

const (
// MachineConfigDiffType is the type of the MachineConfigDiff resource.
// tsgen:MachineConfigDiffType
MachineConfigDiffType = resource.Type("MachineConfigDiffs.omni.sidero.dev")
)

// MachineConfigDiff is the diff between two redacted machine configurations.
type MachineConfigDiff = typed.Resource[MachineConfigDiffSpec, MachineConfigDiffExtension]
Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't name this as RedactedClusterMachineConfigDiff to avoid over-verbosity.


// MachineConfigDiffSpec wraps specs.MachineConfigDiffSpec.
type MachineConfigDiffSpec = protobuf.ResourceSpec[specs.MachineConfigDiffSpec, *specs.MachineConfigDiffSpec]

// MachineConfigDiffExtension provides auxiliary methods for MachineConfigDiff resource.
type MachineConfigDiffExtension struct{}

// ResourceDefinition implements [typed.Extension] interface.
func (MachineConfigDiffExtension) ResourceDefinition() meta.ResourceDefinitionSpec {
return meta.ResourceDefinitionSpec{
Type: MachineConfigDiffType,
DefaultNamespace: resources.DefaultNamespace,
}
}
1 change: 1 addition & 0 deletions client/pkg/omni/resources/omni/omni.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func init() {
registry.MustRegisterResource(KubernetesUpgradeManifestStatusType, &KubernetesUpgradeManifestStatus{})
registry.MustRegisterResource(KubernetesUpgradeStatusType, &KubernetesUpgradeStatus{})
registry.MustRegisterResource(KubernetesVersionType, &KubernetesVersion{})
registry.MustRegisterResource(MachineConfigDiffType, &MachineConfigDiff{})
registry.MustRegisterResource(MachineLabelsType, &MachineLabels{})
registry.MustRegisterResource(MachineType, &Machine{})
registry.MustRegisterResource(MachineClassType, &MachineClass{})
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/api/omni/specs/omni.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,8 @@ export type InfraProviderCombinedStatusSpec = {
description?: string
icon?: string
health?: InfraProviderCombinedStatusSpecHealth
}

export type MachineConfigDiffSpec = {
diff?: string
}
1 change: 1 addition & 0 deletions frontend/src/api/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const ClusterMachineStatusLabelNodeName = "omni.sidero.dev/node-name";
export const ExtensionsConfigurationLabel = "omni.sidero.dev/root-configuration";
export const MachineType = "Machines.omni.sidero.dev";
export const MachineClassType = "MachineClasses.omni.sidero.dev";
export const MachineConfigDiffType = "MachineConfigDiffs.omni.sidero.dev";
export const MachineConfigGenOptionsType = "MachineConfigGenOptions.omni.sidero.dev";
export const MachineExtensionsType = "MachineExtensions.omni.sidero.dev";
export const MachineExtensionsStatusType = "MachineExtensionsStatuses.omni.sidero.dev";
Expand Down
13 changes: 13 additions & 0 deletions internal/backend/grpc/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/siderolabs/omni/client/api/omni/management"
"github.com/siderolabs/omni/client/pkg/omni/resources/infra"
"github.com/siderolabs/omni/client/pkg/omni/resources/omni"
"github.com/siderolabs/omni/client/pkg/omni/resources/siderolink"
"github.com/siderolabs/omni/client/pkg/omni/resources/system"
Expand Down Expand Up @@ -318,6 +319,18 @@ func (s *managementServer) collectClusterResources(ctx context.Context, cluster
rt: omni.DiscoveryAffiliateDeleteTaskType,
listOptions: clusterQuery,
},
{
rt: omni.MachineConfigDiffType,
listOptions: clusterQuery,
},
{
rt: infra.InfraMachineType,
listOptions: clusterQuery,
},
{
rt: infra.InfraMachineStatusType,
listOptions: clusterQuery,
},
Comment on lines +326 to +333
Copy link
Member Author

Choose a reason for hiding this comment

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

Added these two into bundles as well, good to have.

}

machineIDs := map[string]struct{}{}
Expand Down
29 changes: 18 additions & 11 deletions internal/backend/runtime/omni/audit/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ const (

// Data contains the audit data.
type Data struct {
NewUser *NewUser `json:"new_user,omitempty"`
Machine *Machine `json:"machine,omitempty"`
MachineLabels *MachineLabels `json:"machine_labels,omitempty"`
AccessPolicy *AccessPolicy `json:"access_policy,omitempty"`
Cluster *Cluster `json:"cluster,omitempty"`
MachineSet *MachineSet `json:"machine_set,omitempty"`
MachineSetNode *MachineSetNode `json:"machine_set_node,omitempty"`
ConfigPatch *ConfigPatch `json:"config_patch,omitempty"`
TalosAccess *TalosAccess `json:"talos_access,omitempty"`
K8SAccess *K8SAccess `json:"k8s_access,omitempty"`
Session Session `json:"session,omitempty"`
NewUser *NewUser `json:"new_user,omitempty"`
Machine *Machine `json:"machine,omitempty"`
MachineLabels *MachineLabels `json:"machine_labels,omitempty"`
AccessPolicy *AccessPolicy `json:"access_policy,omitempty"`
Cluster *Cluster `json:"cluster,omitempty"`
MachineSet *MachineSet `json:"machine_set,omitempty"`
MachineSetNode *MachineSetNode `json:"machine_set_node,omitempty"`
ConfigPatch *ConfigPatch `json:"config_patch,omitempty"`
MachineConfigDiff *MachineConfigDiff `json:"machine_config_diff,omitempty"`
TalosAccess *TalosAccess `json:"talos_access,omitempty"`
K8SAccess *K8SAccess `json:"k8s_access,omitempty"`
Session Session `json:"session,omitempty"`
}

// Session contains information about the current session.
Expand Down Expand Up @@ -111,6 +112,12 @@ type ConfigPatch struct {
Data string `json:"data,omitempty"`
}

// MachineConfigDiff struct contains information about the machine configuration diff.
type MachineConfigDiff struct {
ID resource.ID `json:"id,omitempty"`
Diff string `json:"diff,omitempty"`
}

// TalosAccess struct contains information about the access to the Talos node.
type TalosAccess struct {
FullMethodName string `json:"full_method_name,omitempty"`
Expand Down
11 changes: 11 additions & 0 deletions internal/backend/runtime/omni/audit/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func Init(a *audit.Log) {
audit.ShouldLogUpdate(a, configPatchUpdate, audit.WithInternalAgent())
audit.ShouldLogUpdateWithConflicts(a, configPatchUpdate, audit.WithInternalAgent())
audit.ShouldLogDestroy(a, omni.ConfigPatchType, configPatchDestroy, audit.WithInternalAgent())

audit.ShouldLogCreate(a, machineConfigDiffCreate, audit.WithInternalAgent())
}

func publicKeyCreate(_ context.Context, data *audit.Data, res *auth.PublicKey, _ ...state.CreateOption) error {
Expand Down Expand Up @@ -389,6 +391,15 @@ func configPatchDestroy(_ context.Context, data *audit.Data, ptr resource.Pointe
return nil
}

func machineConfigDiffCreate(_ context.Context, data *audit.Data, res *omni.MachineConfigDiff, _ ...state.CreateOption) error {
initPtrField(&data.MachineConfigDiff)

data.MachineConfigDiff.ID = res.Metadata().ID()
data.MachineConfigDiff.Diff = res.TypedSpec().Value.Diff

return nil
}

func initPtrField[T any](v **T) {
if *v == nil {
*v = new(T)
Expand Down
Loading
Loading