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

Add space trimming check in ValidateSysctls #11224

Merged
merged 1 commit into from
Aug 17, 2021

Conversation

xatier
Copy link
Contributor

@xatier xatier commented Aug 13, 2021

This is to catch invalid sysctl configs with extra spacing.

See
containers/common#723 (comment)

Signed-off-by: xatier [email protected]

@unknowndevQwQ
Copy link
Contributor

Cloud you consider adding something like this for ulimit?

}
_, err := ValidateSysctls(strSlice)
assert.Error(t, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to add a test that should pass, perhaps:

	strSlice := []string{
		" net.ipv4.ping_group_range=0 0          ",
		"          net.ipv4.ping_group_range=0 0 ",
	}

Also, can you add a check for the error text you're expecting, or at least "extra spaces found" as the substring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TomSweeneyRedHat thanks for suggestions. I was thinking that other tests for ValidateSysctls would still go through my changes, as long as we don't see regressions on the other existing tests I think there's no need to introduce other test cases? I can still add a few if you wish.

Yes, I'll update my PR to check the message as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, this won't be (and shouldn't be, IMO) passing, as we do arr := strings.Split(val, "=") in ValidateSysctls.

    strSliceGood := []string{                                                    
        " net.ipv4.ping_group_range=0 0          ",                              
        "          net.ipv4.ping_group_range=0 0 ",                             
    }                                                                            
    _, err := ValidateSysctls(strSliceGood)                                     
    assert.Nil(t, err)

@xatier
Copy link
Contributor Author

xatier commented Aug 13, 2021

@unknowndevQwQ, I didn't look into that code path too closely, sorry.

Cloud you consider adding something like this for ulimit?


Update:

Just checked briefly on ulimits. It appears to be we are leveraging docker/go-units [1] in containers/common validateUlimits [2]. You may want to submit a PR there.

[1] https://github.com/docker/go-units/blob/master/ulimit.go#L66
[2] https://github.com/containers/common/blob/6c933f226ed44491d082d6d52cbe31ae6fe0e76f/pkg/config/config_local.go#L69

This is to catch invalid sysctl configs with extra spacing.

See
containers/common#723 (comment)

Signed-off-by: xatier <[email protected]>
@xatier
Copy link
Contributor Author

xatier commented Aug 15, 2021

@TomSweeneyRedHat @rhatdan, also once this is merged, I'll create another PR with the same change in containers/common.

https://github.com/containers/common/blob/main/pkg/sysclt/sysctl.go#L30

@rhatdan
Copy link
Member

rhatdan commented Aug 15, 2021

LGTM
Thanks @xatier

@unknowndevQwQ
Copy link
Contributor

It would be nice if there was some way to allow spaces on both sides of the equal sign
For example, sysctl.d allows this

@xatier
Copy link
Contributor Author

xatier commented Aug 17, 2021

@unknowndevQwQ, I believe it makes more sense to stay with more restricted formats (i.e., no space). I am aware sysctl.conf would ignore whitespaces, while traditionally the sysctl cli tool has the wildly used variable=value form.

In container/common, we simply treat this as simple []string type [1], disallowing any additional extra spacing for this would make parsing (and any other sanity checks) a lot less painful. Furthermore, we can eliminate future code bugs similar to [2].

[1] https://github.com/containers/common/blob/main/pkg/config/config.go#L90
[2] containers/common#723

@rhatdan
Copy link
Member

rhatdan commented Aug 17, 2021

/approve

I am fine with either format, this is not going to be a common mistake.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 17, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan, xatier

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 17, 2021
@mheon
Copy link
Member

mheon commented Aug 17, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 17, 2021
@openshift-ci openshift-ci bot merged commit edf9ec3 into containers:main Aug 17, 2021
xatier added a commit to xatier/common that referenced this pull request Aug 17, 2021
xatier added a commit to xatier/common that referenced this pull request Aug 17, 2021
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants