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

OCM-13040 | test: Bastion proxy support username and password #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jameszwang
Copy link
Contributor

No description provided.

systemctl start squid
systemctl enable squid`, cidrBlock)
username := utils.RandomLabel(5)
password := utils.RandomLabel(10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Have a try to see if there is another function can generate password with special characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not find a function which can generate password with special characters, create a new fun named GeneratePassword() to implement it.

username := utils.RandomLabel(5)
password := utils.RandomLabel(10)

hashedPassword, err := generateBcryptPassword(password)
Copy link
Contributor

Choose a reason for hiding this comment

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

Make a generate username and password function. The function is too huge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, create a new func generateWriteSquidPasswordFileCommand() to generate username/password, and put them into squid's password file.

encodeUserData := base64.StdEncoding.EncodeToString([]byte(userData))
return vpc.LaunchBastion("", zone, encodeUserData, keypairName, privateKeyPath)
line := fmt.Sprintf("%s:%s\n", username, hashedPassword)
remoteFilePath := "/etc/squid/passwords"
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't hardcode 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.

Updated, create a const SquidPasswordFilePath.

return vpc.LaunchBastion("", zone, encodeUserData, keypairName, privateKeyPath)
line := fmt.Sprintf("%s:%s\n", username, hashedPassword)
remoteFilePath := "/etc/squid/passwords"
hostName := fmt.Sprintf("%s:22", *instance.PublicIpAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't make it hardcode 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.

Updated, create a const SSHPort

line := fmt.Sprintf("%s:%s\n", username, hashedPassword)
remoteFilePath := "/etc/squid/passwords"
hostName := fmt.Sprintf("%s:22", *instance.PublicIpAddress)
createFileCMD := fmt.Sprintf("sudo touch %s", remoteFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Generate a new function for the username/password written.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, create a new func named generateWriteSquidPasswordFileCommand() to generate username and password.

createFileCMD,
copyPasswordCMD,
}
privateKeyName := fmt.Sprintf("%s-%s", path.Join(privateKeyPath, keypairName), "keyPair.pem")
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the keypath to a common function. Otherwise I have to maintain too many places and it will cause unexpected error during running.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, create a new func GetPrivateKeyName() in aws utils.

log.LogInfo("Found existing bastion: %s", *insts[0].InstanceId)
return &insts[0], nil

proxyUrl = fmt.Sprintf("http://%s:%s@%s:3128", username, password, *instance.PublicIpAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

net/url related packages to use an official function for the url generation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, using net/url construct proxy url.

@xueli181114
Copy link
Contributor

Put more logs to the code blocks.

@jameszwang
Copy link
Contributor Author

Put more logs to the code blocks.

Updated, add info log and error log in related functions.

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