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

LOG-4574: Input permission validation failure with an HTTP receiver as input in a multiple-CLF #2189

Merged
merged 1 commit into from
Oct 3, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func gatherPipelineInputs(clf loggingv1.ClusterLogForwarder) sets.String {
if inputRefs.Has(input.Name) && input.Application != nil {
inputTypes.Insert(loggingv1.InputNameApplication)
}
if input.Receiver != nil && input.Receiver.HTTP != nil {
inputTypes.Insert(loggingv1.InputNameAudit)
}
}

return *inputTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,42 @@ var _ = Describe("[internal][validations] validate clusterlogforwarder permissio
}
Expect(ValidateServiceAccount(customClf, k8sClient, extras)).To(Not(Succeed()))
})

It("should pass validation if service account can collect audit logs and there is an HTTP receiver", func() {
k8sAuditClient := &mockAuditSARClient{
fake.NewClientBuilder().WithObjects(clfServiceAccount).Build(),
}

const httpInputName = `http-receiver`
customClf.Spec = loggingv1.ClusterLogForwarderSpec{
ServiceAccountName: clfServiceAccount.Name,

Inputs: []loggingv1.InputSpec{
{
Name: httpInputName,
Receiver: &loggingv1.ReceiverSpec{
HTTP: &loggingv1.HTTPReceiver{
ReceiverPort: loggingv1.ReceiverPort{
Port: 8080,
TargetPort: 8080,
},
Format: loggingv1.FormatKubeAPIAudit,
},
},
},
},

Pipelines: []loggingv1.PipelineSpec{
{
Name: "pipeline1",
InputRefs: []string{
httpInputName,
},
},
},
}
Expect(ValidateServiceAccount(customClf, k8sAuditClient, extras)).To(Succeed())
})
})

It("should not validate clusterlogforwarder named 'instance' in the namespace 'openshift-logging'", func() {
Expand Down Expand Up @@ -196,3 +232,19 @@ func (c *mockSARClient) Create(ctx context.Context, obj client.Object, opts ...c
}
return nil
}

type mockAuditSARClient struct {
client.Client
}

func (c *mockAuditSARClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
sar, ok := obj.(*authorizationapi.SubjectAccessReview)
if !ok {
return fmt.Errorf("unexpected object type: %T", obj)
}
inputName := sar.Spec.ResourceAttributes.Name
if inputName == loggingv1.InputNameAudit {
sar.Status.Allowed = true
}
return nil
}