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 template.openshift.io/expose annotation for use with tsb bind #14486

Merged
merged 1 commit into from Jun 16, 2017

Conversation

jim-minter
Copy link
Contributor

@jim-minter
Copy link
Contributor Author

[test][testextended][extended:core(templates)]

@jim-minter
Copy link
Contributor Author

@openshift/api-review @pmorie @bparees @jwforres ptal - addition of annotation "template.openshift.io/expose" (name and semantics) as well as template service broker bind response. A sample tsb bind response follows:

{
  "credentials": {
   "Route.route.openshift.io.cakephp-mysql-example.host": "cakephp-mysql-example-demo.router.default.svc.cluster.local",
   "Route.route.openshift.io.cakephp-mysql-example.path": "",
   "Secret.cakephp-mysql-example.database-password": "TkJXRWtUVmdRc1N3ZklKUQ==",
   "Secret.cakephp-mysql-example.database-user": "Y2FrZXBocA==",
   "Service.cakephp-mysql-example.clusterIP": "172.30.113.152",
   "Service.cakephp-mysql-example.port": 8080,
   "Service.cakephp-mysql-example.port.web": 8080
  }
}

@jim-minter jim-minter self-assigned this Jun 6, 2017
@smarterclayton
Copy link
Contributor

smarterclayton commented Jun 6, 2017 via email

@jim-minter jim-minter force-pushed the trello133-tsb-bind branch 2 times, most recently from e96f64c to 2f22b2d Compare June 6, 2017 17:57
@bparees
Copy link
Contributor

bparees commented Jun 6, 2017

Separation between resource and name is questionable. If that's our whole API surface we have a problem of both expressiveness and future proofing.

you mean the lack of separation? the way we concatenated the resource type and the key name?

Our problem is the limitations of the service broker bind credentials api. If we want our credential object to be easily consumed by applications, we really need to stick to flat key/value structures.

Otherwise applications are going to be forced to parse json to extract configs/credentials/service-addresses

This looks like we are abusing the credentials api

how so? because these things are not all credentials? because we're not creating a more sophisticated structure?

@pmorie do we have examples of what other brokers are returning for bind credential objects?

@deads2k
Copy link
Contributor

deads2k commented Jun 7, 2017

you mean the lack of separation? the way we concatenated the resource type and the key name?

That's how I read it and mirrors the comment I was going to post about the key-space. You have no reliable way to know where the end of the group is (dots and dashes are legal in may resource names) so generic parsing is impossible (ambiguous) leading to specific whitelists.

Another issue is that you're choosing your favorite part of the API object and returning back a format tailored for that. If you used a generic format (something like json path from the root for instance), you'd face fewer problems if you later wanted to allow pulling a different value back and the behavior would be generic across any future resource type.

@bparees
Copy link
Contributor

bparees commented Jun 7, 2017

You have no reliable way to know where the end of the group is (dots and dashes are legal in may resource names) so generic parsing is impossible (ambiguous) leading to specific whitelists.

yeah i anticipated this concern(at least that we might have to choose a different separator), but do you have an alternate suggestion? Again we strongly prefer a flat structure because otherwise we're putting a high burden on the applications that consume this content.

Another issue is that you're choosing your favorite part of the API object and returning back a format tailored for that.

if i'm understanding you correctly, this is a complaint about the annotation scheme used for selecting the keys, not the format of the key/value pairs being returned in the credential object.

it's a fair point, but it's also going to make it even harder to sensibly define a key for the content the jsonpath extracts (and of course make life harder for the template authors who have to craft jsonpath expressions now).

Copy link
Contributor

@bparees bparees left a comment

Choose a reason for hiding this comment

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

couple nits otherwise lgtm, @smarterclayton and @deads2k's concerns about the annotation syntax and credential key/value format notwithstanding.

"name": "${NAME}",
"annotations": {
"template.openshift.io/expose": ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I clearly need to find a way to make this readme more visible :(

https://github.com/openshift/origin/blob/master/examples/quickstarts/README.md

Files in this directory are automatically pulled down, do not modify/add files to this directory.

Copy link
Contributor Author

@jim-minter jim-minter Jun 8, 2017

Choose a reason for hiding this comment

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

Snort. How about a file called CONTENT_IN_THIS_DIRECTORY_IS_GENERATED_ELSEWHERE (or whatever)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'm going to leave these changes in the PR for now as one of them is required for the extended test to work. After api-review and before merge I'll send PRs to the upstream repos and run hack/update-external-examples.sh. Can't wait.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good.

"Route.route.openshift.io.myroute.host": route.Spec.Host,
"Route.route.openshift.io.myroute.path": route.Spec.Path,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

no test for "bad" on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, because as things stand the value of expose is currently ignored on routes.

@jim-minter
Copy link
Contributor Author

jim-minter commented Jun 8, 2017

@bparees @openshift/api-review thanks for the feedback, I was psyched that no-one took issue with the annotation name. Anyway, please take another look. I've reworked this to use JSON path and I think the whole thing is better as a result. Sample input:

On a route: "annotations": { "template.openshift.io/expose-uri": "http://{.spec.host}{.spec.path}" }
On a secret: "annotations": { "template.openshift.io/expose-username": "{.data['username']}", "template.openshift.io/expose-password": "{.data['password']}" }

Sample bind result:

{
  "credentials": {
    "uri": "http://cakephp-mysql-example-demo.router.default.svc.cluster.local",
    "username": "user",
    "password": password"
  }
}

(c.f. contents of "credentials" in spec example bind result: https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#response-4)

@jim-minter
Copy link
Contributor Author

ping @openshift/api-review is there any chance of feedback on this today?

@deads2k
Copy link
Contributor

deads2k commented Jun 9, 2017

Can you update the result of the bind call in your first comment? It still looks like you may be suffering from an inconsistent parse problem in those keys. kind.group/name/key would be guaranteed to parse predictably.

@deads2k
Copy link
Contributor

deads2k commented Jun 9, 2017

Can you update the result of the bind call in your first comment? It still looks like you may be suffering from an inconsistent parse problem in those keys. kind.group/name/key would be guaranteed to parse predictably.

Ah, I see you did it in a later comment. That did come out quite a bit nicer.

@jim-minter
Copy link
Contributor Author

@deads2k @smarterclayton but can it get the approved label? The two points I'd highlight on my side:

  1. The same key could be exposed twice, either in the same object or across multiple objects. It might be easiest to doc the results of doing this as being undefined, but if required I could also sort by object type / object name / annotation name to make it well defined which value wins in this circumstance. Please advise if the latter is wanted/a requirement.

  2. Given this is a completely different API to k8s, as a nod to usability I would quite like to straight convert any exposed []byte data (e.g. secret data) to string to hand it back to the service broker without base64 encoding it. The conversion would just be the Golang default one - i.e. interpret the []byte as UTF-8 and insert U+FFFD for any undecodable rune. I think @jwforres also expressed a preference for this. I don't fundamentally mind which way this goes, I just want the nod to get the PR moved on.

@smarterclayton
Copy link
Contributor

For 2, wouldn't that mean that we lose data? UTF -> JSON -> raw is lossy.

@bparees
Copy link
Contributor

bparees commented Jun 9, 2017

Given this is a completely different API to k8s, as a nod to usability I would quite like to straight convert any exposed []byte data (e.g. secret data) to string to hand it back to the service broker without base64 encoding it.

there's no guarantee the byte data can be represented as a non-base64 encoded string. I can put a binary secret into my secret object. I don't see how we can expect to reliably decode the field.

from the Secret api doc:

	// Data contains the secret data.  Each key must be a valid DNS_SUBDOMAIN
	// or leading dot followed by valid DNS_SUBDOMAIN.
	// The serialized form of the secret data is a base64 encoded string,
	// representing the arbitrary (possibly non-string) data value here.
	// +optional
	Data map[string][]byte

@smarterclayton
Copy link
Contributor

I don't even think you can safely encode \x00 for instance.

@jim-minter
Copy link
Contributor Author

I'm just putting out on the table the idea of losing the ability to pass through arbitrary raw binary, for the benefit of people not worrying about their password xyzzy coming through in base64, in what is somewhat an entry level technology anyway. Feel free to say no.

The loss is when the binary can't be decoded into a UTF-8 string. @smarterclayton I think anything UTF-8 is then representable in json including \x00 - Go marshals it to "\u0000", right?

@bparees
Copy link
Contributor

bparees commented Jun 9, 2017

I'm just putting out on the table the idea of losing the ability to pass through arbitrary raw binary, for the benefit of people not worrying about their password xyzzy coming through in base64, in what is somewhat an entry level technology anyway. Feel free to say no.

i don't suppose there's a way to encode into the jsonpath extraction, whether we want the base64 encoded form, or the string form. Potentially it could be encoded into the annotation key itself. (default to strings, but if the annotation key is something like "template.openshift.io/expose-binary-mysecret", then we do a base64 encode instead?)

Barring that, both choices feel bad. Making app developers base64 decode their passwords is bad. Letting people create binary secrets and then not supporting them in the template broker is bad.

@jim-minter
Copy link
Contributor Author

Right now, I'm hearing "base64-encode anything thats []byte under the covers because it's the least worst option that offers fidelity."

BTW, did I say I'd love to have api approval on this before Monday UK time so that this has a chance to merge? 😄

@bparees
Copy link
Contributor

bparees commented Jun 9, 2017

Right now, I'm hearing "base64-encode anything thats []byte under the covers because it's the least worst option that offers fidelity."

i like my secondary annotation option that allows users to choose base64 or string encoding.

@bparees
Copy link
Contributor

bparees commented Jun 9, 2017

@openshift/api-review please sign off on the concept of this annotation(with key suffix)+jsonpath extraction scheme. We can iterate on:

  1. naming
  2. base64 encoding or not (or having 2 annotations, one for base64 and one for string extraction)

as a follow up.

@smarterclayton
Copy link
Contributor

Approved.

@bparees
Copy link
Contributor

bparees commented Jun 9, 2017

@jim-minter squash it and i'll merge.

we can negotiate the binary-content behavior on monday.

@jim-minter
Copy link
Contributor Author

@bparees updated, ptal.

@jim-minter
Copy link
Contributor Author

The following PRs have been opened which should hopefully mean that this PR is mergeable as is, at least from an examples/quickstarts point of view:

sclorg/cakephp-ex#72
sclorg/dancer-ex#61
sclorg/django-ex#89
sclorg/nodejs-ex#125
sclorg/rails-ex#87

Copy link
Contributor

@bparees bparees left a comment

Choose a reason for hiding this comment

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

@jim-minter two nits and then lgtm.

for _, r := range results {
switch len(r) {
case 0:
// shouldn't happen
Copy link
Contributor

Choose a reason for hiding this comment

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

do we not want to at least log an error indicating what the jsonpath was and the object we searched, if this happens then?


default:
// we don't permit individual JSONPath expressions which return
// multiple objects as we haven't decided how these should be output
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be part of the api doc for the annotation. (that the jsonpath expression must select non-compound fields)

@jim-minter
Copy link
Contributor Author

@bparees nits addressed, please merge

@bparees
Copy link
Contributor

bparees commented Jun 13, 2017

[merge]

@jim-minter we need follow up discussion with @openshift/api-review to finalize agreement on:

  1. the annotation name(s)
  2. the binary vs string mechanism
  3. the restriction to primitive value extraction only.

Probably best to open that as a fresh issue and have the discussion there.

@bparees
Copy link
Contributor

bparees commented Jun 13, 2017

at least one of these failures is legit:

--- FAIL: TestEvaluateJSONPathExpression (0.00s)
	bind_test.go:118: 2: error "3 JSONPath results found on annotation a"

@jim-minter
Copy link
Contributor Author

oops, forgot to update error message in unit test - fixed and pushed
[test]

@jim-minter
Copy link
Contributor Author

@bparees tests passed please rehit merge

@bparees
Copy link
Contributor

bparees commented Jun 14, 2017

[merge][severity:blocker]

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2017
@openshift-bot
Copy link
Contributor

openshift-bot commented Jun 16, 2017

continuous-integration/openshift-jenkins/merge Waiting: You are in the build queue at position: 10

@smarterclayton
Copy link
Contributor

Weird [test]

@jim-minter jim-minter removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 16, 2017
@jim-minter
Copy link
Contributor Author

rebased. [test]

@openshift-bot
Copy link
Contributor

Evaluated for origin testextended up to a8b2dba

@bparees
Copy link
Contributor

bparees commented Jun 16, 2017

re[merge][severity:blocker]

@bparees bparees self-assigned this Jun 16, 2017
@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to a8b2dba

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/testextended SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin_extended/638/) (Base Commit: 967d057) (PR Branch Commit: a8b2dba) (Extended Tests: core(templates))

@bparees
Copy link
Contributor

bparees commented Jun 16, 2017 via email

@bparees
Copy link
Contributor

bparees commented Jun 16, 2017 via email

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to a8b2dba

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/2326/) (Base Commit: d40783e) (PR Branch Commit: a8b2dba)

@smarterclayton smarterclayton merged commit 5891474 into openshift:master Jun 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants