Skip to content

Conversation

@joelddiaz
Copy link

Move the api currently stored in github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential into openshift/api/cloudcredential.
Add Makefile hooks for generating deepcopy/CRD.

This is primarily a direct copy over from cloud-credential-operator except for:

  1. a brand new cloudcredential/register.go
  2. a cloudcredential/v1/doc.go with extra annotations
  3. updated path for the k8s:conversion-gen annotation in cloudcredential/v1/register.go
  4. cleaned up cloudcredential/v1/doc.go

The deepcopy has been regenerated, the swagger newly generated, and the CRD generated as well (matches current CRD in openshift/cloud-credential-operator/manifests/00-crd.yaml.

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: joelddiaz
To complete the pull request process, please assign derekwaynecarr
You can assign the PR to them by writing /assign @derekwaynecarr in a comment when ready.

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

Details 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

Joel Diaz added 2 commits July 10, 2020 09:06
specifically the `assert` package
Move the api currently stored in github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential into openshift/api/cloudcredential.
Add Makefile hooks for generating deepcopy/CRD.

This is primarily a direct copy over from cloud-credential-operator except for:
1) a brand new `cloudcredential/register.go`
2) a `cloudcredential/v1/doc.go` with extra annotations
3) updated path for the k8s:conversion-gen annotation in `cloudcredential/v1/register.go`
4) cleaned up `cloudcredential/v1/doc.go`

The deepcopy has been regenerated, the swagger newly generated, and the CRD generated as well (matches current CRD in `openshift/cloud-credential-operator/manifests/00-crd.yaml`.
@joelddiaz joelddiaz force-pushed the cloud-cred-op-types branch from b131f88 to 84068c0 Compare July 10, 2020 13:13
// DeepCopyInto will perform a DeepCopy into the provided AWSProviderSpec
func (in *AWSProviderSpec) DeepCopyInto(out *AWSProviderSpec) {
*out = *in
out.TypeMeta = in.TypeMeta
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this implicit from *out = *in?

// TODO: these types should eventually be broken out, along with the actuator, to a separate repo.

// AWSProviderSpec contains the required information to create a user policy in AWS.
// +k8s:deepcopy-gen=false
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Author

Choose a reason for hiding this comment

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

The field in AWSProviderSpec.StatementEntries[].PolicyCondition being of type map[string]map[string]interface{}. This means we cannot generate DeepCopy. The interface{} unfortunately snuck into our API while DeepCopy generation was mistakenly turned off (restored in openshift/cloud-credential-operator#204 ).

Copy link
Contributor

Choose a reason for hiding this comment

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

Just create custom deepcopy funcs for IAMPolicyCondition or even IAMPolicyConditionKeyValue. Doesn't that work? No need to disable generation for these normal structs.

// Action describes the particular AWS service actions that should be allowed or denied. (i.e. ec2:StartInstances, iam:ChangePassword)
Action []string `json:"action"`
// Resource specifies the object(s) this statement should apply to. (or "*" for all)
Resource string `json:"resource"`
Copy link
Contributor

Choose a reason for hiding this comment

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

should any of these be required?

Copy link
Author

Choose a reason for hiding this comment

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

I suppose we could default to "*" if Resource is not set, but I'm not thrilled with the idea that by default we would be granting permissions with the least restrictions possible. If there were a workable minimum-permissions-by-default, I could definitely see making this not required.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to require any of these, they seem optional, similarly how we do in audit. But defaulting to * is not a good idea. Default should be empty which means none.

Copy link
Author

Choose a reason for hiding this comment

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

@soltysh sorry, getting back to this after some other unrelated work. If we mark this optional, and the empty string is treated as None, is there any value in defining a list of permissions and then saying that you can perform all those actions against nothing? What have we gained by making the field optional?

Copy link
Author

Choose a reason for hiding this comment

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

Question: since this is an embedded type hidden behind a RawExtension, what effect does annotating these fields have?

// +k8s:deepcopy-gen=false
type StatementEntry struct {
// Effect indicates if this policy statement is to Allow or Deny.
Effect string `json:"effect"`
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an enum? Add kubebuilder markers.

Copy link
Author

Choose a reason for hiding this comment

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

I believe today the only allowed values are "Allow" or "Deny" so I supposes we can make this an enum.

Copy link
Author

Choose a reason for hiding this comment

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

Same question here, for an embedded type behind a RawExtension, what effect does annotating these fields have? (I annotated it as an enum, and there was no difference in the generated CRD which confused me until I realized this was behind the spec.providerSpec RawExtension.)

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a kubebuilder question. It might have special code to generate a RawExtensins schema.

User string `json:"user"`
// Policy is the name of the policy attached to the user in AWS.
Policy string `json:"policy"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

anything required?

Copy link
Author

Choose a reason for hiding this comment

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

None of the status fields are required. When cloud-cred-operator is running in "passthrough" mode, no users are created, and no policies are created. The credentials are simply copied as-is from the secret kube-system/aws-creds.


// IAMPolicyConditionKeyValue - mapping of values for the chosen type
// +k8s:deepcopy-gen=false
type IAMPolicyConditionKeyValue map[string]interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

what are the values? Arbitrary JSON? It needs kubebuilder markers for that (x-kubernetes-preserve-unknown-fields).

Copy link
Author

Choose a reason for hiding this comment

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

Yes, to the cloud-cred-operator, this is basically arbitrary (and IMO quite complex https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html ) JSON that just gets passed through to the AWS API calls as-is. I'll work on adding the markers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Compare the JSON type here: https://github.com/kubernetes/apiextensions-apiserver/blob/master/pkg/apis/apiextensions/v1/types_jsonschema.go#L59

You migth want to replicate what it does with a custom deepcopy func.


// IAMPolicyCondition - map of condition types, with associated key - value mapping
// +k8s:deepcopy-gen=false
type IAMPolicyCondition map[string]IAMPolicyConditionKeyValue
Copy link
Contributor

Choose a reason for hiding this comment

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

why no deepcopy?

Copy link
Author

Choose a reason for hiding this comment

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

Again, the interface{} messes up the auto DeepCopy generation here.


"k8s.io/apimachinery/pkg/runtime"

"github.com/stretchr/testify/assert"
Copy link
Contributor

Choose a reason for hiding this comment

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

The goal of this repo is to have minimal set of dependencies, I'd prefer to use go built-in mechanism over fancy assert libraries here.

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this copyright note, we have the license file at the root of this repo and that's sufficient.

// Action describes the particular AWS service actions that should be allowed or denied. (i.e. ec2:StartInstances, iam:ChangePassword)
Action []string `json:"action"`
// Resource specifies the object(s) this statement should apply to. (or "*" for all)
Resource string `json:"resource"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to require any of these, they seem optional, similarly how we do in audit. But defaulting to * is not a good idea. Default should be empty which means none.

)

// NewScheme creates a new Scheme
func NewScheme() (*runtime.Scheme, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is quite unexpected here. Eventual codecs should be created where this is being used, not in API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like we should move this back to the CCO repo @joelddiaz

&AWSProviderStatus{}, &AWSProviderSpec{},
&AzureProviderStatus{}, &AzureProviderSpec{},
&GCPProviderStatus{}, &GCPProviderSpec{},
&VSphereProviderStatus{}, &VSphereProviderSpec{},
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems off. The usual k8s api is to have:

  • spec - what user specified
  • status - what the controller achieved

but in your case spec and status are separate, why? I believe this can't be changed at the moment but I must admit this is unexpected.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks suspicious, all of these cloud specific types are embedded in the CredentialsRequest RawExtensions. I'm wondering if we need to add these as known types at all. It might be related to serialization as we do have to decode them in the cloud specific actuators.

Copy link
Contributor

Choose a reason for hiding this comment

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

If these types are embedded I don't think they should be part of openshift/api at all.

Copy link
Author

Choose a reason for hiding this comment

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

I actually considered removing this in the CCO repo (openshift/cloud-credential-operator#219) as prep-work before opening this PR, but it was never merged. I can certainly resurrect that PR and stop registering these types.

@openshift-ci-robot
Copy link

@joelddiaz: PR needs rebase.

Details

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.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 22, 2020
@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci-robot openshift-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 15, 2020
@openshift-bot
Copy link

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci-robot openshift-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 15, 2020
@openshift-bot
Copy link

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci-robot
Copy link

@openshift-bot: Closed this PR.

Details

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants