Skip to content

Commit

Permalink
ssh signer interface throwing rest exceptions for errors (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
havetisyan authored Aug 29, 2018
1 parent e46f0e6 commit 1dcbd1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public interface SSHSigner {
* @param principal Principal requesting the ssh certificates
* @param certRequest SSH Certificate Request
* @param instanceId Instance ID of the origin host
* @return SSH Certificates
* @return SSH Certificates. Any error conditions are handled
* by throwing com.yahoo.athenz.common.rest.ResourceExceptions
*/
default SSHCertificates generateCertificate(Principal principal, SSHCertRequest certRequest,
final String instanceId) {
Expand All @@ -38,7 +39,8 @@ default SSHCertificates generateCertificate(Principal principal, SSHCertRequest
/**
* Retrieve the SSH Signer certificate for the given type
* @param type signer type: user or host
* @return SSH Signer Certificate
* @return SSH Signer Certificate. Any error conditions are handled
* by throwing com.yahoo.athenz.common.rest.ResourceExceptions
*/
default String getSignerCertificate(String type) {
return null;
Expand Down
24 changes: 17 additions & 7 deletions servers/zts/src/main/java/com/yahoo/athenz/zts/ZTSImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2563,20 +2563,30 @@ public SSHCertificates postSSHCertRequest(ResourceContext ctx, SSHCertRequest ce
AthenzObject.SSH_CERT_REQUEST.convertToLowerCase(certRequest);
logPrincipal(ctx);

Object timerMetric = metric.startTiming(callerTiming, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
metric.increment(HTTP_REQUEST);
metric.increment(caller, ZTSConsts.ZTS_UNKNOWN_DOMAIN);

// generate our ssh certificate
// get our principal and domain values

final Principal principal = ((RsrcCtxWrapper) ctx).principal();
final String domainName = principal.getDomain();

Object timerMetric = metric.startTiming(callerTiming, domainName);
metric.increment(HTTP_REQUEST);
metric.increment(caller, domainName);

// if we have a certificate then we'll try to extract
// the instance id for our request

final String instanceId = X509CertUtils.extractRequestInstanceId(principal.getX509Certificate());
SSHCertificates certs = instanceCertManager.getSSHCertificates(principal,
certRequest, instanceId);

// generate our certificate. the ssh signer interface throws
// rest ResourceExceptions so we'll catch and log those

SSHCertificates certs = null;
try {
certs = instanceCertManager.getSSHCertificates(principal,
certRequest, instanceId);
} catch (com.yahoo.athenz.common.server.rest.ResourceException ex) {
throw error(ex.getCode(), ex.getMessage(), caller, domainName);
}

metric.stopTiming(timerMetric);
return certs;
Expand Down

0 comments on commit 1dcbd1c

Please sign in to comment.