Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Only redact Kinds starting "Secret.", avoiding SealedSecret and similar #78

Merged

Conversation

puzza007
Copy link
Contributor

@puzza007 puzza007 commented Jan 28, 2019

Fixes the error below for e.g. SealedSecret.v1alpha1.bitnami.com

Traceback (most recent call last):
  File "/Users/po/src/kubediff/kubediff", line 48, in <module>
    main()
  File "/Users/po/src/kubediff/kubediff", line 42, in main
    failed = check_files(args, printer, config)
  File "/Users/po/src/kubediff/kubedifflib/_diff.py", line 246, in check_files
    differences += check_file(printer, path, config)
  File "/Users/po/src/kubediff/kubedifflib/_diff.py", line 174, in check_file
    printer.diff(path, difference)
  File "/Users/po/src/kubediff/kubedifflib/_diff.py", line 214, in diff
    self._write('%s', difference.to_text(self._current.kind))
  File "/Users/po/src/kubediff/kubedifflib/_diff.py", line 35, in to_text
    message = self.message % ((len(self.args[0]) * '*'), (len(self.args[1]) * '*'))
TypeError: object of type 'NoneType' has no len()

@dimitropoulos
Copy link

dimitropoulos commented Feb 11, 2019

any reason not to just do

if kind.startswith('Secret.') and len(self.args) == 2:

?

that, after all, seems to be closer to what the code is intending, with the additional benefit of not causing a bug later if secrets are ever versioned at v2.

@puzza007 puzza007 force-pushed the restrict-secrets-diff-to-secrets-v1 branch from 2c4ebbb to a359d8b Compare February 12, 2019 00:02
@puzza007
Copy link
Contributor Author

Nope! That's definitely better. I've force pushed that change.

@bboreham
Copy link
Contributor

It seems to me the failure arises because args has not been set up the way the code expects, so tweaking the spelling of "secret" is not really getting to the heart of the matter.

Why not check args ? How does it arise that args can be set different ways ? Is that an issue ?

@torz you added this code - do you have a view ?

Can we have tests for the various cases?

@dimitropoulos
Copy link

dimitropoulos commented Feb 12, 2019

@bboreham my interpretation is that the previous code falsely assumed that there would not be another kubernetes resource that contains the word "secret" as a substring. for example when debugging on this line we see that kind has the value Secret.v1. for a kubernetes Secret resource, and something like SealedSecret.v1. for a kubernetes SealedSecret resource. This code will then wrongly take a codepath that was written to handle Secrets for a SealedSecret. @puzza007 do you agree with that synopsis? I'm running a test now with a SealedSecret to verify.

@dimitropoulos
Copy link

dimitropoulos commented Feb 12, 2019

I can confirm that kind in this function is SealedSecret.v1alpha1.bitnami.com for a SealedSecret resource. What's curious about that to me is that there's no . afterwards like with a regular Secret. Here's a table just to lay it out (I added some other resources as a reference point):

Resource Kind API Version to_text kind
Secret v1 Secret.v1.
SealedSecret bitnami.com/v1alpha1 SealedSecret.v1alpha1.bitnami.com
Deployment extensions/v1beta1 Deployment.v1beta1.extensions
Service v1 Service.v1.
DaemonSet apps/v1 DaemonSet.v1.apps
PriorityClass scheduling.k8s.io/v1beta1 PriorityClass.v1beta1.scheduling.k8s.io
ClusterRole rbac.authorization.k8s.io/v1 ClusterRole.v1.rbac.authorization.k8s.io
HelmRelease flux.weave.works/v1beta1 HelmRelease.v1beta1.flux.weave.works
Pod v1 Pod.v1.

in short, and at the least, this code seems to be .-separating something that already (on occasion, but not most often) has .s in it...

that's why there's a . at the end of a secret resource because there is no namespace (e.g. extensions for a Deployment) to put at the end - so it's blank.

the pattern seems to be:
Resource kind . apiVersion version . apiVersion namespace
with the caveats (perhaps two separate bugs) that it seems to assume that:

  1. there will always be an apiVersion namespace (where there isn't for Secrets, for example)
  2. (by virtue of the fact that the kind is . separated) there will not be a . in the apiVersion namespace

@puzza007
Copy link
Contributor Author

puzza007 commented Feb 12, 2019 via email

@rade
Copy link
Member

rade commented Feb 12, 2019

I believe what you call 'namespace' here, kubernetes calls 'group'. From https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get

TYPE[.VERSION][.GROUP]

Presumably neither type nor group are permitted to contain ., whereas version is, hence there is no ambiguity.

To Bryan's point though... what is args? What ensures that when resource kind is of type Secret (regardless of version and group), and there are two args, then args[0] and args[1] are things on which len can be invoked?

@bboreham
Copy link
Contributor

It's trying to print out %s != %s with the yaml and Kubernetes values as first and second arg, and in this specific crash the yaml value is "null" which reads into Python as None.

@dimitropoulos dimitropoulos force-pushed the restrict-secrets-diff-to-secrets-v1 branch from a359d8b to 7c2dac6 Compare February 14, 2019 16:40
@awh
Copy link
Contributor

awh commented Feb 14, 2019

@puzza007 has #82 fixed your crash? If so, can we retitle this PR as a fix for #81?

@puzza007
Copy link
Contributor Author

Hi @awh. I've just tried with 12ef0a3 and it works for me 👍

@bboreham bboreham changed the title Avoid Difference.to_text error on kinds containing secret Only redact Kinds starting "Secret.", avoiding SealedSecret and similar Mar 5, 2019
@bboreham bboreham merged commit 3f71485 into weaveworks:master Apr 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants