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

asset/installconfig: improve validation of user inputs #711

Merged
merged 15 commits into from
Dec 15, 2018
Merged

asset/installconfig: improve validation of user inputs #711

merged 15 commits into from
Dec 15, 2018

Conversation

staebler
Copy link
Contributor

@staebler staebler commented Nov 21, 2018

For most of the validation, bespoke code has been removed in lieu of calling code that already exists and is more widely used.

  • Base Domain: Use kubernetes validation of rfc-1123 sub-domains, with the addition that the base domain can end with a dot. This change removes the ability to use uppercase letters in the base domain.
  • Cluster Name: Use kubernetes validation of rfc-1123 sub-domains. This change removes the restriction that each label in the cluster name is at most 63 characters long.
  • Pull Secret: Validate that (1) there is an "auths" field, (2) the "auths" value has fields, and (3) each field in the "auth" value has an "auth" or a "credsStore" field.
  • SSH Public Key: Use ParseAuthorizedKey from golang.org/x/crypto/ssh to validate that the provided ssh key can be parsed.

Validation has been added to the InstallConfig asset to enforce that the install-config.yml file loaded is valid. Some fields have been modified to make this easier. For example, the CIDR fields that were strings had their types changed to ipnet.IPNet.

Fixes https://jira.coreos.com/browse/CORS-850
Fixes https://jira.coreos.com/browse/CORS-941
Fixes #910

@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 21, 2018
@@ -249,51 +122,6 @@ func TestEmail(t *testing.T) {
})
}
}
func TestCIDRsDontOverlap(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be useful to validate cluster and service cidrs do not overlap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add some validation to install-config.yml.

Copy link
Contributor

Choose a reason for hiding this comment

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

@staebler any progress on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The implementation for install-config.yml validation is done and add to this PR. I have a bunch of unit tests that I need to create for it still, so I have marked this PR as WIP while I finish those.

@staebler staebler changed the title pkg/asset/installconfig: improve validation of user inputs WIP: pkg/asset/installconfig: improve validation of user inputs Nov 28, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 28, 2018

// ParseCIDRMust parses a CIDR from its string representation. If the parse fails,
// the function will panic.
func ParseCIDRMust(s string) *IPNet {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: MustParseCIDR

Copy link
Contributor

@crawford crawford left a comment

Choose a reason for hiding this comment

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

A few of the commit titles also need to be shorted slightly. I would leave pkg/ off of the scope since we know where the assets live (the scope doesn't need to be a path).

pkg/asset/installconfig/aws/aws.go Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 3, 2018
@staebler staebler changed the title WIP: pkg/asset/installconfig: improve validation of user inputs asset/installconfig: improve validation of user inputs Dec 4, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 4, 2018
@staebler
Copy link
Contributor Author

staebler commented Dec 6, 2018

/retest

@eparis
Copy link
Member

eparis commented Dec 11, 2018

@abhinavdahiya
Copy link
Contributor

abhinavdahiya commented Dec 13, 2018

@staebler commits 1971857 .. 5bddc88 are /lgtm

I am a little concerned with addition of gomock and gomock generated files.

  • How do we regenerate them?
  • How do we ensure they are always up to date (), new test in ci / or go test ./... is going to catch that?

@staebler
Copy link
Contributor Author

@abhinavdahiya Some documentation around running unit tests and re-generating mock files has been added to CONTRIBUTING.md.

@abhinavdahiya
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 14, 2018
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 14, 2018
@abhinavdahiya
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 14, 2018

Some unit tests use mocks that are generated with gomock. If the underlying interface for a mock changes, then the mock will need to be regenerated. Use the following to regenerate all of the mocks under the pkg package.

```
Copy link
Member

Choose a reason for hiding this comment

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

nit: this and the following fenced block should use:

```sh

Because they're shell excerpts. But we can fix that in follow-up work.

valid: false,
},
{
name: "missing worker machine pool",
Copy link
Member

Choose a reason for hiding this comment

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

Should this be allowed? We can create worker pools as a day-2 operation, can't we?

Copy link
Contributor

@abhinavdahiya abhinavdahiya Dec 14, 2018

Choose a reason for hiding this comment

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

currently our install fails if we do not have workers. So this is required for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember it failing at one point without workers defined in the install config. That may have been resolved since I originally wrote it. I'll dig into it further, and if we succeed without workers defined, then I will file a follow-up PR.

installConfig: func() *types.InstallConfig {
c := validInstallConfig()
c.Machines = append(c.Machines, types.MachinePool{
Name: "other",
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to support this. See here.

Copy link
Contributor

@abhinavdahiya abhinavdahiya Dec 14, 2018

Choose a reason for hiding this comment

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

hive team is going to be making that change soon, they can change the tests.
also right now we have nothing that supports adding these random pools.

Use kubernetes validation of rfc-1123 sub-domains, with the
addition that the base domain can end with a dot. This change removes the
ability to use uppercase letters in the base domain.

https://jira.coreos.com/browse/CORS-850
Validate that (1) there is an "auths" field, (2) the "auths"
value has fields, and (3) each field in the "auth" value has
an "auth" or a "credsStore" field.

https://jira.coreos.com/browse/CORS-850
Use ParseAuthorizedKey from golang.org/x/crypto/ssh to validate that
the provided ssh key can be parsed.

https://jira.coreos.com/browse/CORS-850
The validation functions use golang.org/x/crypto/ssh to validate the ssh
key provided.

https://jira.coreos.com/browse/CORS-850
Move the uri validation from pkg/asset/installconfig/libvirt to pkg/validation
for consistency with other validation functions.

https://jira.coreos.com/browse/CORS-850
Much of the code that made of the CIDR validation was there to give a custom
description of what made the CIDR provided invalid. This has been removed in
favor of using the error returned by the golang library's ParseCIDR function.

Additionally, the code to determine whether two CIDRs overlap was unnecessary
complex because it did not take advantage of the fact that CIDRs only overlap
if one is a subset of the other.

https://jira.coreos.com/browse/CORS-850
When an InstallConfig asset is loaded from an on-disk file, validate that
the fields of the InstallConfig have appropriate values. This uses all the
same validations that are down on the user-provided assets upon which the
InstalConfig asset depends as well as addition validations on other fields.

#711
The emailaddress asset is no longer used as of commit e7aaedb.
Remove validation functions that are no longer being used.

https://jira.coreos.com/browse/CORS-850
Add gomock to use to mock asset.FileFetcher in unit tests that load assets.

https://jira.coreos.com/browse/CORS-850
…nfig.yml

Move the fetching of openstack platform values to types/openstack/validation
so that it can be used to validate values in the install-config.yml as well.

https://jira.coreos.com/browse/CORS-888
@wking
Copy link
Member

wking commented Dec 15, 2018

looks like this needs another rebase

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 15, 2018
@staebler
Copy link
Contributor Author

looks like this needs another rebase

Rebased to fix conflicts with #654.

cc @abhinavdahiya @wking

@abhinavdahiya
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 15, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinavdahiya, staebler

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:
  • OWNERS [abhinavdahiya,staebler]

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

@abhinavdahiya
Copy link
Contributor

/retest

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Dec 15, 2018

@staebler: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-libvirt af073f9 link /test e2e-libvirt

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@wking
Copy link
Member

wking commented Dec 15, 2018

Router timed out.

/retest

@openshift-merge-robot openshift-merge-robot merged commit 874876e into openshift:master Dec 15, 2018
wking added a commit to wking/openshift-installer that referenced this pull request Dec 15, 2018
Covering 5813f61 (Merge pull request openshift#745 from wking/s3-vpc-endpoint,
2018-12-13) through 874876e (Merge pull request openshift#711 from
staebler/improve_input_validation, 2018-12-14).
wking added a commit to wking/hive that referenced this pull request Dec 19, 2018
Catching up with openshift/installer@b2d6fa40 (validate: simplify CIDR
validation, 2018-11-27, openshift/installer#711).
wking added a commit to wking/openshift-installer that referenced this pull request Dec 19, 2018
And rename to 'Regions', since the target package is already about
validation.  ValidRegions was added to the aws package in b2d6fa4
(validate: simplify CIDR validation, 2018-11-27, openshift#711), but it's just
used for validation and it isn't a type defintion.
wking added a commit to wking/hive that referenced this pull request Dec 19, 2018
Catching up with openshift/installer@b2d6fa40 (validate: simplify CIDR
validation, 2018-11-27, openshift/installer#711).
wking added a commit to wking/hive that referenced this pull request Dec 19, 2018
Catching up with openshift/installer@b2d6fa40 (validate: simplify CIDR
validation, 2018-11-27, openshift/installer#711).

We can't convert the v1alpha1 type to an *IPNet, because it doesn't
have DeepCopyInto methods [1]:

  go vet ./pkg/... ./cmd/... ./contrib/...
  # github.com/openshift/hive/pkg/apis/hive/v1alpha1
  pkg/apis/hive/v1alpha1/zz_generated.deepcopy.go:87:8: (*in).DeepCopyInto undefined (type *ipnet.IPNet has no field or method DeepCopyInto)

We used to define those methods in the installer, but stopped in
openshift/installer@ca6f6195 (Revert "pkg/ipnet: Add DeepCopy and
DeepCopyInto for IPNet", 2018-09-20, openshift/installer#295).

[1]: https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_hive/144/pull-ci-openshift-hive-master-unit/253/build-log.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants