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

GCF support for Java #2209

Merged
merged 2 commits into from
Jun 28, 2023
Merged

Conversation

gilad-bendor
Copy link
Contributor

No description provided.

Signed-off-by: gilad.bendor <gilad.bendor@yahooinc.com>
new DERIA5String(athenzService + '.' + athenzDomain.replace('.', '-') + '.' + certDomain)),
new GeneralName(
GeneralName.dNSName,
new DERIA5String("gcf-" + gcpProjectId + '-' + athenzService + ".instanceid.athenz." + certDomain)), // TODO: Not sure about this
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should no longer use this sanDns entry. instead we we should use sanUri to specify the instance id.

we need to be careful of the order as the spiffe URI must be the first uri in the cert. So add the following entry at the end of this block:

athenz://instanceid/%s/gcp-function-%s", provider, gcpProjectId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the current code:

        return new GeneralName[]{
                new GeneralName(
                        GeneralName.dNSName,
                        new DERIA5String(athenzService + '.' + athenzDomain.replace('.', '-') + '.' + certDomain)),
                new GeneralName(
                        GeneralName.dNSName,
                        new DERIA5String("gcf-" + gcpProjectId + '-' + athenzService + ".instanceid.athenz." + certDomain)),    // TODO: Not sure about this
                new GeneralName(
                        GeneralName.uniformResourceIdentifier,
                        new DERIA5String("spiffe://" + athenzDomain + "/sa/" + athenzService)),
        };

Here is the best I can come up with (provider = "sys.gcp." + gcpRegion):

        return new GeneralName[]{
                new GeneralName(
                        GeneralName.uniformResourceIdentifier,
                        new DERIA5String("spiffe://" + athenzDomain + "/sa/" + athenzService)),
                new GeneralName(
                        GeneralName.uniformResourceIdentifier,
                        new DERIA5String("athenz://instanceid/" + provider + "/gcp-function-" + gcpProjectId)),
        };

Can you confirm?


/** Used to parse ZTS response */
@JsonIgnoreProperties(ignoreUnknown = true)
private static class InstanceIdentity {
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason why we have this class here? we already have all the classes defined in athenz-zts-core. So let's use com.yahoo.athenz.zts.InstanceIdentity instead of defining this class here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

public String x509CertificateSigner;
}

static String ATTESTATION_DATA_URL_PREFIX = "http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?format=full&audience=";
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's be consistent with all other classes in the project. define these 3 variables at the top of the class definition and not at the bottom.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

static String ATTESTATION_DATA_URL_PREFIX = "http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?format=full&audience=";

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Copy link
Collaborator

Choose a reason for hiding this comment

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

we have this LOG object defined yet all of the log statements are commented out. If we're not planning any log entries, let's remove this and the dependency otherwise, let's enable the log statements. Be careful about the identity token ones - let's make sure we don't have any tokens logged even in debug mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...all logs reluctantly removed... ;-)

.build()) {

// Construct an HTTP POST request.
String postPayload = "{" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's not generate the payload manually by generating the json here. We already have a model classes defined in athenz-zts-core.

Let's define a com.yahoo.athenz.zts.InstanceRegisterInformation object, set the values in the object and then we can convert that object into json or I believe there are other Entity object setters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* @param gcpProjectId GCP project-id that the function runs in
* @param athenzProvider name of the provider service for GCP Cloud-Functions
* @param ztsUrl Something like: https://...:.../zts/v1
* @param certDomain TODO: Abhijeet - explain what this is...
Copy link
Collaborator

Choose a reason for hiding this comment

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

certDomain - string identifying the dns domain for generating SAN fields. for example, for a domain with sports and service api and certdomain athenz.io, the sanDNS entry in the certificate will be set to api.sports.athenz.io

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* @param optionalLocality Optional field in the certificate's Subject.
* @param optionalOrganization Optional field in the certificate's Subject.
* @param optionalOrganizationUnit Optional field in the certificate's Subject.
* @return GCPFunctionIdentity with private key and certificate
Copy link
Collaborator

Choose a reason for hiding this comment

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

it returns PrivateAndCertificate and not GCPFunctionIdentity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

public static int ATTESTATION_READ_TIMEOUT_MS = ZTS_READ_TIMEOUT_MS;

/** Response of {@link #getGCPFunctionServiceCertificate} */
public static class PrivateAndCertificate {
Copy link
Collaborator

Choose a reason for hiding this comment

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

golang uses X509KeyPair as the object name that includes the private key and certificate so how about using that instead of PrivateAndCertificate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


// Build the certificate's Subject fields - as a single string.
// At the end, certDn would look something like this: "c=US, s=CA, ou=Eng"
// Build the certificate's Subject fields - as a single string.
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment is duplicated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

String athenzProvider,
String ztsUrl,
String certDomain,
String optionalCountry,
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should not include optional in the field names to identity the field as optional - these are already included in the javadocs. let's just include rdn instead of optional to identity that these are relative distinguished name components - e.g. rdnCountry, rdnState, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Signed-off-by: gilad.bendor <gilad.bendor@yahooinc.com>
Copy link
Collaborator

@havetisyan havetisyan left a comment

Choose a reason for hiding this comment

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

will address some minor changes in a subsequent PR

@havetisyan havetisyan merged commit 03ae368 into AthenZ:master Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants