-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add granular control of SELinux labels for host mounts #19839
Changes from all commits
94cab10
24731b5
89c867b
6ac6be8
2d86cca
43bf61b
f882746
a765057
bacccf6
1cb6ef0
d1c9a4d
2575729
4e6d4da
dfbfea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
client/volumes: Add a mount volume level option for selinux tags on volumes | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
package structs | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/ci" | ||
|
@@ -168,3 +169,63 @@ func TestVolumeMount_Equal(t *testing.T) { | |
Apply: func(vm *VolumeMount) { vm.PropagationMode = "mode2" }, | ||
}}) | ||
} | ||
|
||
func TestVolumeMount_Validate(t *testing.T) { | ||
ci.Parallel(t) | ||
|
||
testCases := []struct { | ||
name string | ||
expectedErr error | ||
volMount *VolumeMount | ||
}{ | ||
{ | ||
name: "valid volume mount", | ||
volMount: &VolumeMount{ | ||
Volume: "vol", | ||
}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "empty volume reference", | ||
volMount: &VolumeMount{ | ||
Volume: "", | ||
}, | ||
expectedErr: errVolMountEmptyVol, | ||
}, | ||
{ | ||
name: "invalid propagation mode", | ||
volMount: &VolumeMount{ | ||
Volume: "vol", | ||
PropagationMode: "very invalid propagation mode", | ||
}, | ||
expectedErr: errVolMountInvalidPropagationMode, | ||
}, | ||
{ | ||
name: "invalid selinux label", | ||
volMount: &VolumeMount{ | ||
Volume: "vol", | ||
PropagationMode: VolumeMountPropagationPrivate, | ||
SELinuxLabel: "very invalid selinux label", | ||
}, | ||
expectedErr: errVolMountInvalidSELinuxLabel, | ||
}, | ||
{ | ||
name: "full valid volume mont", | ||
volMount: &VolumeMount{ | ||
Volume: "vol", | ||
PropagationMode: VolumeMountPropagationPrivate, | ||
SELinuxLabel: SELinuxPrivateVolume, | ||
}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.volMount.Validate() | ||
if !errors.Is(err, tc.expectedErr) { | ||
t.Fatalf("expected error %v, got %v", tc.expectedErr, err) | ||
} | ||
Comment on lines
+225
to
+228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be shortened to something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must.ErrorIs doesn't work here, probably something with the unwarpping of the errors |
||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of how this error looks like? I'm not sure why we do it in some many parts of the code, but appending directly to
mErr.Errors
usually results in a bad error hierarchy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is actually called in the task group validation test, it should not be a problem