Skip to content

Validate project-id returned from metadata server#2822

Merged
yihanzhen merged 8 commits intogoogleapis:masterfrom
yihanzhen:check_projectid_from_metadataserver
Feb 1, 2018
Merged

Validate project-id returned from metadata server#2822
yihanzhen merged 8 commits intogoogleapis:masterfrom
yihanzhen:check_projectid_from_metadataserver

Conversation

@yihanzhen
Copy link
Contributor

Validate project-id returned from metadata server to handle cases in which a descriptive failure html page is returned instead of the project-id itself from server when projects are not running in google cloud machines.

which a descriptive failure html page is returned instead of the
projectid itself from server when projects are not running in google cloud machines.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 30, 2018
@yihanzhen yihanzhen requested a review from pongad January 30, 2018 22:03
* Returns true if the projectId is valid.
* projectId must be between 6 and 30 characters
* projectId can have lowercase letters, digits or hyphens
* and must start with a lowercase letter

This comment was marked as spam.

* and must start with a lowercase letter
*/
private boolean isValidProjectId(String projectId) {
Pattern p = Pattern.compile("^[a-z][a-z0-9-]*$");

This comment was marked as spam.

This comment was marked as spam.

* projectId can have lowercase letters, digits or hyphens
* and must start with a lowercase letter
*/
private boolean isValidProjectId(String projectId) {

This comment was marked as spam.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Jan 31, 2018
which a descriptive failure html page is returned instead of the
projectid itself from server when projects are not running in google cloud machines.
@yihanzhen yihanzhen force-pushed the check_projectid_from_metadataserver branch from a934449 to 7ab63f1 Compare January 31, 2018 18:49
@yihanzhen
Copy link
Contributor Author

PTAL

private static final RetrySettings NO_RETRY_SETTINGS = getDefaultRetrySettingsBuilder()
.setMaxAttempts(1).build();

private static final Pattern projectIdPattern = Pattern.compile("^[a-z][a-z0-9-]*[a-z0-9]+$");

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

assertThat(ServiceOptions.isValidProjectId(validProjectId)).isTrue();
assertThat(ServiceOptions.isValidProjectId(invalidProjectId1)).isFalse();
assertThat(ServiceOptions.isValidProjectId(invalidProjectId2)).isFalse();
assertThat(ServiceOptions.isValidProjectId(invalidProjectId3)).isFalse();

This comment was marked as spam.

@yihanzhen
Copy link
Contributor Author

PTAL

Copy link

@wsh wsh left a comment

Choose a reason for hiding this comment

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

As it is, this change introduces a bug (it will reject project IDs with colons in them). Please consider reverting the merge.

&& !projectId.endsWith("-");
}

private static boolean isLowerCase(char c) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return c >= 'a' && c <= 'z';
}

private static boolean isDigit(char c) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return false;
}
}
return projectId.length() > 0 && isLowerCase(projectId.charAt(0))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* method is primarily used to protect against DNS hijacking.
*/
static boolean isValidProjectId(String projectId) {
for (char c : projectId.toCharArray()) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

yihanzhen added a commit to yihanzhen/google-cloud-java that referenced this pull request Feb 1, 2018
yihanzhen added a commit that referenced this pull request Feb 1, 2018
chingor13 pushed a commit that referenced this pull request Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: no This human has *not* signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants