Skip to content
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

Update owner reference #85

Merged
merged 2 commits into from
Jun 4, 2024
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
2 changes: 1 addition & 1 deletion internal/behavior/preprocessor/apparmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (p *DataPreprocessor) converProfileToParents(profile string) string {
return profile
}

// Returns the operation type if known, unkown otherwise.
// Returns the operation type if known, unknown otherwise.
func (p *DataPreprocessor) opType(event *varmortypes.AaLogRecord) string {
if strings.HasPrefix(event.Operation, "file_") ||
strings.HasPrefix(event.Operation, "inode_") ||
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var (
// WebhookSelectorLabel is used for matching the admission requests
WebhookSelectorLabel = map[string]string{}

// OmuxSocketPath is used for recieving the audit logs of AppArmor from rsyslog
// OmuxSocketPath is used for receiving the audit logs of AppArmor from rsyslog
OmuxSocketPath = "/var/run/varmor/audit/omuxsock.sock"
)

Expand Down
9 changes: 9 additions & 0 deletions internal/policy/clusterpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ func (c *ClusterPolicyController) handleUpdateVarmorClusterPolicy(newVp *varmor.

logger.Info("2.3. update ArmorProfile")
oldAp.Spec = *newApSpec
forceSetOwnerReference(oldAp, newVp, true)
_, err = c.varmorInterface.ArmorProfiles(oldAp.Namespace).Update(context.Background(), oldAp, metav1.UpdateOptions{})
if err != nil {
logger.Error(err, "ArmorProfile().Update()")
return err
}
} else if len(oldAp.OwnerReferences) == 0 {
// Forward compatibility, add an ownerReference to the existing ArmorProfile object
forceSetOwnerReference(oldAp, newVp, true)
_, err = c.varmorInterface.ArmorProfiles(oldAp.Namespace).Update(context.Background(), oldAp, metav1.UpdateOptions{})
if err != nil {
logger.Error(err, "ArmorProfile().Update()")
Expand Down
11 changes: 10 additions & 1 deletion internal/policy/policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,16 @@ func (c *PolicyController) handleUpdateVarmorPolicy(newVp *varmor.VarmorPolicy,

logger.Info("2.3. update ArmorProfile")
oldAp.Spec = *newApSpec
_, err = c.varmorInterface.ArmorProfiles(newVp.Namespace).Update(context.Background(), oldAp, metav1.UpdateOptions{})
forceSetOwnerReference(oldAp, newVp, false)
_, err = c.varmorInterface.ArmorProfiles(oldAp.Namespace).Update(context.Background(), oldAp, metav1.UpdateOptions{})
if err != nil {
logger.Error(err, "ArmorProfile().Update()")
return err
}
} else if len(oldAp.OwnerReferences) == 0 {
// Forward compatibility, add an ownerReference to the existing ArmorProfile object
forceSetOwnerReference(oldAp, newVp, false)
_, err = c.varmorInterface.ArmorProfiles(oldAp.Namespace).Update(context.Background(), oldAp, metav1.UpdateOptions{})
if err != nil {
logger.Error(err, "ArmorProfile().Update()")
return err
Expand Down
27 changes: 27 additions & 0 deletions internal/policy/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,30 @@ func updateWorkloadAnnotationsAndEnv(
}
}
}

func forceSetOwnerReference(ap *varmor.ArmorProfile, obj interface{}, clusterScope bool) {
controller := true
if clusterScope {
vcp := obj.(*varmor.VarmorClusterPolicy)
ap.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: "crd.varmor.org/v1beta1",
Kind: "VarmorClusterPolicy",
Name: vcp.Name,
UID: vcp.UID,
Controller: &controller,
},
}
} else {
vp := obj.(*varmor.VarmorPolicy)
ap.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: "crd.varmor.org/v1beta1",
Kind: "VarmorPolicy",
Name: vp.Name,
UID: vp.UID,
Controller: &controller,
},
}
}
}
2 changes: 1 addition & 1 deletion internal/status/api/v1/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (m *StatusManager) updateAllCRStatus(logger logr.Logger) {
return
}

// Get the list of nodes where the agent is running.
// Get the list of nodes where the agents are running.
nodes, err := m.retrieveNodeNameList()
if err != nil {
logger.Error(err, "m.retrieveNodeNameList()")
Expand Down
Loading