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

enable authenticate for /instance endpoint #775

Merged
merged 1 commit into from Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions clients/go/zts/zts_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -411,6 +411,10 @@ public Identity postOSTKInstanceRefreshRequest(String domain, String service, OS
public InstanceIdentity postInstanceRegisterInformation(InstanceRegisterInformation info, java.util.Map<String, java.util.List<String>> headers) {
WebTarget target = base.path("/instance");
Invocation.Builder invocationBuilder = target.request("application/json");
if (credsHeader != null) {
invocationBuilder = credsHeader.startsWith("Cookie.") ? invocationBuilder.cookie(credsHeader.substring(7),
credsToken) : invocationBuilder.header(credsHeader, credsToken);
}
Response response = invocationBuilder.post(javax.ws.rs.client.Entity.entity(info, "application/json"));
int code = response.getStatus();
switch (code) {
Expand Down
2 changes: 2 additions & 0 deletions core/zts/src/main/java/com/yahoo/athenz/zts/ZTSSchema.java
Expand Up @@ -565,8 +565,10 @@ private static Schema build() {
;

sb.resource("InstanceRegisterInformation", "POST", "/instance")
.comment("we have an authenticate enabled for this endpoint but in most cases the service owner might need to make it optional by setting the zts servers no_auth_uri list to include this endpoint. We need the authenticate in case the request comes with a client certificate and the provider needs to know who that principal was in the client certificate")
.input("info", "InstanceRegisterInformation", "")
.output("Location", "location", "String", "return location for subsequent patch requests")
.auth("", "", true)
.expected("CREATED")
.exception("BAD_REQUEST", "ResourceError", "")

Expand Down
7 changes: 7 additions & 0 deletions core/zts/src/main/rdl/Instance.rdli
Expand Up @@ -36,10 +36,17 @@ type InstanceIdentity Struct {
Map<String,String> attributes (optional); //other config-like attributes determined at boot time
}

// we have an authenticate enabled for this endpoint but in most
// cases the service owner might need to make it optional by setting
// the zts servers no_auth_uri list to include this endpoint. We
// need the authenticate in case the request comes with a client
// certificate and the provider needs to know who that principal
// was in the client certificate
resource InstanceIdentity POST "/instance" {
InstanceRegisterInformation info;
String location (header="Location", out); //return location for subsequent patch requests
expected CREATED;
authenticate;
exceptions {
ResourceError BAD_REQUEST;
ResourceError FORBIDDEN;
Expand Down
Expand Up @@ -421,6 +421,7 @@ public Identity postOSTKInstanceRefreshRequest(@PathParam("domain") String domai
public Response postInstanceRegisterInformation(InstanceRegisterInformation info) {
try {
ResourceContext context = this.delegate.newResourceContext(this.request, this.response);
context.authenticate();
return this.delegate.postInstanceRegisterInformation(context, info);
} catch (ResourceException e) {
int code = e.getCode();
Expand Down