Merge pull request #2389 from kolyshkin/golangci-v2
Switch to golangci-lint v2, cleanup config, fix new linter warnings
This commit is contained in:
commit
d093d6c769
|
|
@ -11,7 +11,7 @@ on:
|
||||||
permissions: read-all
|
permissions: read-all
|
||||||
|
|
||||||
env:
|
env:
|
||||||
LINT_VERSION: v1.64.8
|
LINT_VERSION: v2.0
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
codespell:
|
codespell:
|
||||||
|
|
@ -37,13 +37,13 @@ jobs:
|
||||||
sudo apt-get -qq update
|
sudo apt-get -qq update
|
||||||
sudo apt-get -qq install libseccomp-dev
|
sudo apt-get -qq install libseccomp-dev
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v7
|
||||||
with:
|
with:
|
||||||
version: "${{ env.LINT_VERSION }}"
|
version: "${{ env.LINT_VERSION }}"
|
||||||
args: --verbose
|
args: --verbose
|
||||||
# Extra linters, only checking new code from a pull request.
|
# Extra linters, only checking new code from a pull request.
|
||||||
- name: lint-extra
|
- name: lint-extra
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v7
|
||||||
with:
|
with:
|
||||||
args: --config=.golangci-extra.yml
|
args: --config=.golangci-extra.yml
|
||||||
version: "${{ env.LINT_VERSION }}"
|
version: "${{ env.LINT_VERSION }}"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@
|
||||||
# The idea is to impose additional rules for newly added code only
|
# The idea is to impose additional rules for newly added code only
|
||||||
# (rules we can not realistically satisfy for existing code).
|
# (rules we can not realistically satisfy for existing code).
|
||||||
|
|
||||||
|
version: "2"
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
timeout: 5m
|
||||||
build-tags:
|
build-tags:
|
||||||
- apparmor
|
- apparmor
|
||||||
- seccomp
|
- seccomp
|
||||||
|
|
@ -14,9 +17,13 @@ run:
|
||||||
- systemd
|
- systemd
|
||||||
- exclude_graphdriver_btrfs
|
- exclude_graphdriver_btrfs
|
||||||
- containers_image_openpgp
|
- containers_image_openpgp
|
||||||
timeout: 5m
|
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
default: none
|
||||||
enable:
|
enable:
|
||||||
- godot
|
- godot
|
||||||
|
- staticcheck
|
||||||
|
settings:
|
||||||
|
staticcheck:
|
||||||
|
checks:
|
||||||
|
- all
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
---
|
version: "2"
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
timeout: 5m
|
||||||
build-tags:
|
build-tags:
|
||||||
- apparmor
|
- apparmor
|
||||||
- seccomp
|
- seccomp
|
||||||
|
|
@ -8,81 +10,80 @@ run:
|
||||||
- exclude_graphdriver_btrfs
|
- exclude_graphdriver_btrfs
|
||||||
- containers_image_openpgp
|
- containers_image_openpgp
|
||||||
- cni
|
- cni
|
||||||
timeout: 5m
|
|
||||||
linters:
|
|
||||||
enable-all: true
|
|
||||||
disable:
|
|
||||||
# linters explicitly disabled for the below mentioned reasons ...
|
|
||||||
- funlen # too aggressive/wishful size/statement limit
|
|
||||||
- gochecknoinits # too many hard to fix init() funcs across the code
|
|
||||||
- gocognit # too aggressive default
|
|
||||||
- wsl # useful but too opinionated
|
|
||||||
# others to be re-enabled one-by-one ...
|
|
||||||
- goconst
|
|
||||||
- godox
|
|
||||||
- lll
|
|
||||||
- nestif
|
|
||||||
- cyclop
|
|
||||||
- depguard
|
|
||||||
- errchkjson
|
|
||||||
- errname
|
|
||||||
- errorlint
|
|
||||||
- exhaustive
|
|
||||||
- gochecknoglobals
|
|
||||||
- err113
|
|
||||||
- nolintlint
|
|
||||||
- wrapcheck
|
|
||||||
- varnamelen
|
|
||||||
- testpackage
|
|
||||||
- tenv
|
|
||||||
- tagliatelle
|
|
||||||
- stylecheck
|
|
||||||
- paralleltest
|
|
||||||
- nonamedreturns
|
|
||||||
- nlreturn
|
|
||||||
- nakedret
|
|
||||||
- musttag
|
|
||||||
- maintidx
|
|
||||||
- ireturn
|
|
||||||
- exhaustruct
|
|
||||||
- gosec
|
|
||||||
- godot
|
|
||||||
- gocyclo
|
|
||||||
- dogsled
|
|
||||||
- tparallel
|
|
||||||
- thelper
|
|
||||||
- mnd #way to many false positives
|
|
||||||
- nilnil
|
|
||||||
- nilerr
|
|
||||||
- interfacebloat
|
|
||||||
- forcetypeassert
|
|
||||||
- gomoddirectives
|
|
||||||
- testifylint # way to many issues to fix right now, however it is a great linter for better test errors
|
|
||||||
- inamedparam # opinionated style
|
|
||||||
linters-settings:
|
|
||||||
errcheck:
|
|
||||||
check-type-assertions: true
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 35
|
|
||||||
gofmt:
|
|
||||||
rewrite-rules:
|
|
||||||
- pattern: 'interface{}'
|
|
||||||
replacement: 'any'
|
|
||||||
revive:
|
|
||||||
rules:
|
|
||||||
- name: dot-imports
|
|
||||||
disabled: true
|
|
||||||
|
|
||||||
issues:
|
formatters:
|
||||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
enable:
|
||||||
exclude-rules:
|
- gofumpt
|
||||||
# Exclude some linters from running on tests files.
|
|
||||||
- path: _test\.go
|
linters:
|
||||||
linters:
|
enable:
|
||||||
- dupl
|
- asasalint
|
||||||
- perfsprint
|
- asciicheck
|
||||||
# Exclude "should pass the context parameter" for libimage.LookupImage because of backward compatibility.
|
- bidichk
|
||||||
- path: "libimage"
|
- bodyclose
|
||||||
text: "LookupImage"
|
- canonicalheader
|
||||||
linters:
|
- containedctx
|
||||||
- contextcheck
|
- contextcheck
|
||||||
|
- copyloopvar
|
||||||
|
- decorder
|
||||||
|
- dupl
|
||||||
|
- dupword
|
||||||
|
- durationcheck
|
||||||
|
- exptostd
|
||||||
|
- fatcontext
|
||||||
|
- forbidigo
|
||||||
|
- ginkgolinter
|
||||||
|
- gocheckcompilerdirectives
|
||||||
|
- gochecksumtype
|
||||||
|
- gocritic
|
||||||
|
- goprintffuncname
|
||||||
|
- gosmopolitan
|
||||||
|
- iface
|
||||||
|
- intrange
|
||||||
|
- makezero
|
||||||
|
- mirror
|
||||||
|
- misspell
|
||||||
|
- nilnesserr
|
||||||
|
- noctx
|
||||||
|
- nosprintfhostport
|
||||||
|
- perfsprint
|
||||||
|
- prealloc
|
||||||
|
- predeclared
|
||||||
|
- reassign
|
||||||
|
- recvcheck
|
||||||
|
- revive
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- usestdlibvars
|
||||||
|
- usetesting
|
||||||
|
- wastedassign
|
||||||
|
- whitespace
|
||||||
|
settings:
|
||||||
|
errcheck:
|
||||||
|
check-type-assertions: true
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 35
|
||||||
|
revive:
|
||||||
|
rules:
|
||||||
|
- name: dot-imports
|
||||||
|
disabled: true
|
||||||
|
staticcheck:
|
||||||
|
checks:
|
||||||
|
- all
|
||||||
|
- -ST1003 # https://staticcheck.dev/docs/checks/#ST1003 Poorly chosen identifier.
|
||||||
|
- -QF1008 # https://staticcheck.dev/docs/checks/#QF1008 Omit embedded fields from selector expression.
|
||||||
|
exclusions:
|
||||||
|
generated: strict
|
||||||
|
presets:
|
||||||
|
- comments
|
||||||
|
- common-false-positives
|
||||||
|
- std-error-handling
|
||||||
|
rules:
|
||||||
|
- linters:
|
||||||
|
- dupl
|
||||||
|
- perfsprint
|
||||||
|
path: _test\.go
|
||||||
|
- linters:
|
||||||
|
- contextcheck
|
||||||
|
path: libimage
|
||||||
|
text: LookupImage
|
||||||
|
|
|
||||||
|
|
@ -463,13 +463,13 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
|
||||||
skipRemove := false
|
skipRemove := false
|
||||||
numNames := len(i.Names())
|
numNames := len(i.Names())
|
||||||
|
|
||||||
// NOTE: the `numNames == 1` check is not only a performance
|
// NOTE: the `numNames != 1` check is not only a performance
|
||||||
// optimization but also preserves existing Podman/Docker behaviour.
|
// optimization but also preserves existing Podman/Docker behaviour.
|
||||||
// If image "foo" is used by a container and has only this tag/name,
|
// If image "foo" is used by a container and has only this tag/name,
|
||||||
// an `rmi foo` will not untag "foo" but instead attempt to remove the
|
// an `rmi foo` will not untag "foo" but instead attempt to remove the
|
||||||
// entire image. If there's a container using "foo", we should get an
|
// entire image. If there's a container using "foo", we should get an
|
||||||
// error.
|
// error.
|
||||||
if !(referencedBy == "" || numNames == 1) {
|
if referencedBy != "" && numNames != 1 {
|
||||||
byID := strings.HasPrefix(i.ID(), referencedBy)
|
byID := strings.HasPrefix(i.ID(), referencedBy)
|
||||||
byDigest := strings.HasPrefix(referencedBy, "sha256:")
|
byDigest := strings.HasPrefix(referencedBy, "sha256:")
|
||||||
if !options.Force {
|
if !options.Force {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
|
||||||
|
|
||||||
// Give a decent error message if nothing above worked.
|
// Give a decent error message if nothing above worked.
|
||||||
// we want the colon here for the multiline error
|
// we want the colon here for the multiline error
|
||||||
//nolint:revive
|
//nolint:revive,staticcheck
|
||||||
loadError := errors.New("payload does not match any of the supported image formats:")
|
loadError := errors.New("payload does not match any of the supported image formats:")
|
||||||
for _, err := range loadErrors {
|
for _, err := range loadErrors {
|
||||||
loadError = fmt.Errorf("%v\n * %v", loadError, err)
|
loadError = fmt.Errorf("%v\n * %v", loadError, err)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func NormalizeName(name string) (reference.Named, error) {
|
||||||
|
|
||||||
// Enforce "localhost" if needed.
|
// Enforce "localhost" if needed.
|
||||||
registry := reference.Domain(named)
|
registry := reference.Domain(named)
|
||||||
if !(strings.ContainsAny(registry, ".:") || registry == "localhost") {
|
if !strings.ContainsAny(registry, ".:") && registry != "localhost" {
|
||||||
name = toLocalImageName(ref.String())
|
name = toLocalImageName(ref.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ func (r *Runtime) searchImageInRegistry(ctx context.Context, term, registry stri
|
||||||
paramsArr := []SearchResult{}
|
paramsArr := []SearchResult{}
|
||||||
for i := range limit {
|
for i := range limit {
|
||||||
// Check whether query matches filters
|
// Check whether query matches filters
|
||||||
if !(filterMatchesAutomatedFilter(&options.Filter, results[i]) && filterMatchesOfficialFilter(&options.Filter, results[i]) && filterMatchesStarFilter(&options.Filter, results[i])) {
|
if !filterMatchesAutomatedFilter(&options.Filter, results[i]) || !filterMatchesOfficialFilter(&options.Filter, results[i]) || !filterMatchesStarFilter(&options.Filter, results[i]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
official := ""
|
official := ""
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ func (n *cniNetwork) loadNetworks() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !types.NameRegex.MatchString(conf.Name) {
|
if !types.NameRegex.MatchString(conf.Name) {
|
||||||
logrus.Warnf("CNI config list %s has invalid name, skipping: %v", file, types.RegexError)
|
logrus.Warnf("CNI config list %s has invalid name, skipping: %v", file, types.ErrInvalidName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ func CreateBridge(n NetUtil, network *types.Network, usedNetworks []*net.IPNet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !types.NameRegex.MatchString(network.NetworkInterface) {
|
if !types.NameRegex.MatchString(network.NetworkInterface) {
|
||||||
return fmt.Errorf("bridge name %s invalid: %w", network.NetworkInterface, types.RegexError)
|
return fmt.Errorf("bridge name %s invalid: %w", network.NetworkInterface, types.ErrInvalidName)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func CommonNetworkCreate(n NetUtil, network *types.Network) error {
|
||||||
// validate the name when given
|
// validate the name when given
|
||||||
if network.Name != "" {
|
if network.Name != "" {
|
||||||
if !types.NameRegex.MatchString(network.Name) {
|
if !types.NameRegex.MatchString(network.Name) {
|
||||||
return fmt.Errorf("network name %s invalid: %w", network.Name, types.RegexError)
|
return fmt.Errorf("network name %s invalid: %w", network.Name, types.ErrInvalidName)
|
||||||
}
|
}
|
||||||
if _, err := n.Network(network.Name); err == nil {
|
if _, err := n.Network(network.Name); err == nil {
|
||||||
return fmt.Errorf("network name %s already used: %w", network.Name, types.ErrNetworkExists)
|
return fmt.Errorf("network name %s already used: %w", network.Name, types.ErrNetworkExists)
|
||||||
|
|
|
||||||
|
|
@ -294,10 +294,7 @@ func createIpvlanOrMacvlan(network *types.Network) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
driver := network.Driver
|
driver := network.Driver
|
||||||
isMacVlan := true
|
isMacVlan := driver != types.IPVLANNetworkDriver
|
||||||
if driver == types.IPVLANNetworkDriver {
|
|
||||||
isMacVlan = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// always turn dns off with macvlan, it is not implemented in netavark
|
// always turn dns off with macvlan, it is not implemented in netavark
|
||||||
// and makes little sense to support with macvlan
|
// and makes little sense to support with macvlan
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ func (n *netavarkNetwork) loadNetworks() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !types.NameRegex.MatchString(network.Name) {
|
if !types.NameRegex.MatchString(network.Name) {
|
||||||
logrus.Warnf("Network config %q has invalid name: %q, skipping: %v", path, network.Name, types.RegexError)
|
logrus.Warnf("Network config %q has invalid name: %q, skipping: %v", path, network.Name, types.ErrInvalidName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -682,7 +682,7 @@ func openSlirp4netnsPort(apiSocket, proto, hostip string, hostport, guestport ui
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot marshal JSON for slirp4netns: %w", err)
|
return fmt.Errorf("cannot marshal JSON for slirp4netns: %w", err)
|
||||||
}
|
}
|
||||||
if _, err := conn.Write([]byte(fmt.Sprintf("%s\n", data))); err != nil {
|
if _, err := fmt.Fprintf(conn, "%s\n", data); err != nil {
|
||||||
return fmt.Errorf("cannot write to control socket %s: %w", apiSocket, err)
|
return fmt.Errorf("cannot write to control socket %s: %w", apiSocket, err)
|
||||||
}
|
}
|
||||||
//nolint:errcheck // This cast should never fail, if it does we get a interface
|
//nolint:errcheck // This cast should never fail, if it does we get a interface
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,10 @@ var (
|
||||||
// NameRegex is a regular expression to validate names.
|
// NameRegex is a regular expression to validate names.
|
||||||
// This must NOT be changed.
|
// This must NOT be changed.
|
||||||
NameRegex = regexp.Delayed("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
|
NameRegex = regexp.Delayed("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
|
||||||
// RegexError is thrown in presence of an invalid name.
|
// ErrInvalidName is thrown in presence of an invalid name.
|
||||||
RegexError = fmt.Errorf("names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*: %w", ErrInvalidArg) // nolint:revive // This lint is new and we do not want to break the API.
|
ErrInvalidName = fmt.Errorf("names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*: %w", ErrInvalidArg)
|
||||||
|
// Deprecated: use [ErrInvalidName] instead.
|
||||||
|
RegexError = ErrInvalidName
|
||||||
|
|
||||||
// NotHexRegex is a regular expression to check if a string is
|
// NotHexRegex is a regular expression to check if a string is
|
||||||
// a hexadecimal string.
|
// a hexadecimal string.
|
||||||
|
|
|
||||||
|
|
@ -173,10 +173,10 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO
|
||||||
if opts.StdinPassword {
|
if opts.StdinPassword {
|
||||||
var stdinPasswordStrBuilder strings.Builder
|
var stdinPasswordStrBuilder strings.Builder
|
||||||
if opts.Password != "" {
|
if opts.Password != "" {
|
||||||
return errors.New("Can't specify both --password-stdin and --password")
|
return errors.New("can't specify both --password-stdin and --password")
|
||||||
}
|
}
|
||||||
if opts.Username == "" {
|
if opts.Username == "" {
|
||||||
return errors.New("Must provide --username with --password-stdin")
|
return errors.New("must provide --username with --password-stdin")
|
||||||
}
|
}
|
||||||
scanner := bufio.NewScanner(opts.Stdin)
|
scanner := bufio.NewScanner(opts.Stdin)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ func MoveUnderCgroup(cgroup, subtree string, processes []uint32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// root cgroup, skip it
|
// root cgroup, skip it
|
||||||
if parts[2] == "/" && !(unifiedMode && parts[1] == "") {
|
if parts[2] == "/" && (!unifiedMode || parts[1] != "") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,7 +261,7 @@ func MoveUnderCgroup(cgroup, subtree string, processes []uint32) error {
|
||||||
|
|
||||||
if len(processes) > 0 {
|
if len(processes) > 0 {
|
||||||
for _, pid := range processes {
|
for _, pid := range processes {
|
||||||
if _, err := f.WriteString(fmt.Sprintf("%d\n", pid)); err != nil {
|
if _, err := fmt.Fprintf(f, "%d\n", pid); err != nil {
|
||||||
logrus.Debugf("Cannot move process %d to cgroup %q: %v", pid, newCgroup, err)
|
logrus.Debugf("Cannot move process %d to cgroup %q: %v", pid, newCgroup, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func (s *ConfigMapManager) Store(name string, data []byte, driverType string, dr
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(len(data) > 0 && len(data) < maxConfigMapSize) {
|
if len(data) == 0 || len(data) >= maxConfigMapSize {
|
||||||
return "", errDataSize
|
return "", errDataSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ func DeviceFromPath(device string) ([]devices.Device, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if unshare.IsRootless() && src != dst {
|
if unshare.IsRootless() && src != dst {
|
||||||
return nil, fmt.Errorf("Renaming device %s to %s is not supported in rootless containers", src, dst)
|
return nil, fmt.Errorf("renaming device %s to %s is not supported in rootless containers", src, dst)
|
||||||
}
|
}
|
||||||
srcInfo, err := os.Stat(src)
|
srcInfo, err := os.Stat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func IfNecessary(ctx context.Context, operation func() error, options *Options)
|
||||||
logrus.Warnf("Failed, retrying in %s ... (%d/%d). Error: %v", delay, attempt+1, options.MaxRetry, err)
|
logrus.Warnf("Failed, retrying in %s ... (%d/%d). Error: %v", delay, attempt+1, options.MaxRetry, err)
|
||||||
select {
|
select {
|
||||||
case <-time.After(delay):
|
case <-time.After(delay):
|
||||||
break
|
// Do nothing.
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ func (s *SecretsManager) Store(name string, data []byte, driverType string, opti
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(len(data) > 0 && len(data) < maxSecretSize) {
|
if len(data) == 0 || len(data) >= maxSecretSize {
|
||||||
return "", errDataSize
|
return "", errDataSize
|
||||||
}
|
}
|
||||||
var secr *Secret
|
var secr *Secret
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func TestAddSecretAndLookupData(t *testing.T) {
|
||||||
|
|
||||||
s, _, err = manager.LookupSecretData("mysecret")
|
s, _, err = manager.LookupSecretData("mysecret")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if s.CreatedAt == s.UpdatedAt {
|
if s.CreatedAt.Equal(s.UpdatedAt) {
|
||||||
t.Errorf("error: secret CreatedAt should not equal UpdatedAt after a Replace")
|
t.Errorf("error: secret CreatedAt should not equal UpdatedAt after a Replace")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ func addSubscriptionsFromMountsFile(filePath, mountLabel, containerRunDir string
|
||||||
func containerHasEtcSystemFips(subscriptionsDir, mountPoint string) (bool, error) {
|
func containerHasEtcSystemFips(subscriptionsDir, mountPoint string) (bool, error) {
|
||||||
containerEtc, err := securejoin.SecureJoin(mountPoint, "etc")
|
containerEtc, err := securejoin.SecureJoin(mountPoint, "etc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Container /etc resolution error: %w", err)
|
return false, fmt.Errorf("container /etc resolution error: %w", err)
|
||||||
}
|
}
|
||||||
if fileutils.Lexists(filepath.Join(containerEtc, "system-fips")) != nil {
|
if fileutils.Lexists(filepath.Join(containerEtc, "system-fips")) != nil {
|
||||||
logrus.Debug("/etc/system-fips does not exist in the container, not creating /run/secrets/system-fips")
|
logrus.Debug("/etc/system-fips does not exist in the container, not creating /run/secrets/system-fips")
|
||||||
|
|
@ -331,7 +331,7 @@ func containerHasEtcSystemFips(subscriptionsDir, mountPoint string) (bool, error
|
||||||
|
|
||||||
fipsFileTarget, err := securejoin.SecureJoin(mountPoint, "etc/system-fips")
|
fipsFileTarget, err := securejoin.SecureJoin(mountPoint, "etc/system-fips")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Container /etc/system-fips resolution error: %w", err)
|
return false, fmt.Errorf("container /etc/system-fips resolution error: %w", err)
|
||||||
}
|
}
|
||||||
if fipsFileTarget != filepath.Join(mountPoint, subscriptionsDir, "system-fips") {
|
if fipsFileTarget != filepath.Join(mountPoint, subscriptionsDir, "system-fips") {
|
||||||
logrus.Warnf("/etc/system-fips exists in the container, but is not a symlink to %[1]v/system-fips; not creating %[1]v/system-fips", subscriptionsDir)
|
logrus.Warnf("/etc/system-fips exists in the container, but is not a symlink to %[1]v/system-fips; not creating %[1]v/system-fips", subscriptionsDir)
|
||||||
|
|
@ -448,24 +448,24 @@ func addFIPSMounts(mounts *[]rspec.Mount, containerRunDir, mountPoint, mountLabe
|
||||||
destPolicyConfig := "/etc/crypto-policies/config"
|
destPolicyConfig := "/etc/crypto-policies/config"
|
||||||
srcPolicyConfigOnHost, err := securejoin.SecureJoin(mountPoint, srcPolicyConfig)
|
srcPolicyConfigOnHost, err := securejoin.SecureJoin(mountPoint, srcPolicyConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not expand %q in container: %w", srcPolicyConfig, err)
|
return fmt.Errorf("could not expand %q in container: %w", srcPolicyConfig, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = fileutils.Exists(srcPolicyConfigOnHost); err != nil {
|
if err = fileutils.Exists(srcPolicyConfigOnHost); err != nil {
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
return fmt.Errorf("Could not check whether %q exists in container: %w", srcPolicyConfig, err)
|
return fmt.Errorf("could not check whether %q exists in container: %w", srcPolicyConfig, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// /usr/share/crypto-policies/default-fips-config does not exist, let's create it ourselves
|
// /usr/share/crypto-policies/default-fips-config does not exist, let's create it ourselves
|
||||||
cryptoPoliciesConfigFile := filepath.Join(containerRunDir, "fips-config")
|
cryptoPoliciesConfigFile := filepath.Join(containerRunDir, "fips-config")
|
||||||
if err := os.WriteFile(cryptoPoliciesConfigFile, []byte("FIPS\n"), 0o644); err != nil {
|
if err := os.WriteFile(cryptoPoliciesConfigFile, []byte("FIPS\n"), 0o644); err != nil {
|
||||||
return fmt.Errorf("Failed to write fips config file in container for FIPS mode: %w", err)
|
return fmt.Errorf("failed to write fips config file in container for FIPS mode: %w", err)
|
||||||
}
|
}
|
||||||
if err = label.Relabel(cryptoPoliciesConfigFile, mountLabel, false); err != nil {
|
if err = label.Relabel(cryptoPoliciesConfigFile, mountLabel, false); err != nil {
|
||||||
return fmt.Errorf("Failed to apply correct labels on fips config file: %w", err)
|
return fmt.Errorf("failed to apply correct labels on fips config file: %w", err)
|
||||||
}
|
}
|
||||||
if err := os.Chown(cryptoPoliciesConfigFile, uid, gid); err != nil {
|
if err := os.Chown(cryptoPoliciesConfigFile, uid, gid); err != nil {
|
||||||
return fmt.Errorf("Failed to chown fips config file: %w", err)
|
return fmt.Errorf("failed to chown fips config file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
srcPolicyConfigOnHost = cryptoPoliciesConfigFile
|
srcPolicyConfigOnHost = cryptoPoliciesConfigFile
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,9 @@ func GetTimestamp(value string, reference time.Time) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var format string
|
var format string
|
||||||
// if the string has a Z or a + or three dashes use parse otherwise use parseinlocation
|
// If the string has a Z, or a +, or three dashes,
|
||||||
parseInLocation := !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3)
|
// then use time.Parse, otherwise use time.ParseInLocation.
|
||||||
|
parseInLocation := !strings.ContainsAny(value, "zZ+") && strings.Count(value, "-") != 3
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(value, "."):
|
case strings.Contains(value, "."):
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ import (
|
||||||
// It returns the path of the created /etc/localtime file if needed.
|
// It returns the path of the created /etc/localtime file if needed.
|
||||||
func ConfigureContainerTimeZone(timezone, containerRunDir, mountPoint, etcPath, containerID string) (localTimePath string, err error) {
|
func ConfigureContainerTimeZone(timezone, containerRunDir, mountPoint, etcPath, containerID string) (localTimePath string, err error) {
|
||||||
var timezonePath string
|
var timezonePath string
|
||||||
switch {
|
switch timezone {
|
||||||
case timezone == "":
|
case "":
|
||||||
return "", nil
|
return "", nil
|
||||||
case timezone == "local":
|
case "local":
|
||||||
timezonePath, err = filepath.EvalSymlinks("/etc/localtime")
|
timezonePath, err = filepath.EvalSymlinks("/etc/localtime")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("finding local timezone for container %s: %w", containerID, err)
|
return "", fmt.Errorf("finding local timezone for container %s: %w", containerID, err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue