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

Add DatabaseAuthenticationConfig and other changes for improved passwordless db configuration #40

Merged
merged 8 commits into from
Oct 18, 2023

Conversation

chad-cwc
Copy link
Contributor

@chad-cwc chad-cwc commented Oct 6, 2023

This PR updates the SDK as needed for the passwordless database UX improvements I added to the back end. In the API changes, the DatabaseAuthenticationConfig fields are all typed as strings and are not individually validated on the back end; however, the entire object is validated as being one supported by the BastionZero service. For convenience in writing client code, the valid values for each field defined in DatabaseAuthenticationConfig are provided as constants in the dbauthconfig package.

Related webshell-backend PR: https://github.com/bastionzero/webshell-backend/pull/1639

@chad-cwc chad-cwc added the enhancement New feature or request label Oct 6, 2023
@chad-cwc chad-cwc self-assigned this Oct 6, 2023
@chad-cwc chad-cwc changed the title updates required by pwdb improvements Add DatabaseAuthenticationConfig and other changes for improved passwordless db configuration Oct 6, 2023
@chad-cwc chad-cwc requested a review from ymarcus93 October 10, 2023 18:31
// RemotePort is required for all databases except GCP-hosted ones. For GCP-hosted databases,
// Port.Value can be specified but will be ignored when connecting to the database.
// If not provided when creating a CGP database target, Port.Value will be set to 0.
RemotePort *Port `json:"remotePort,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This used to be Port and no omitempty. I think we should keep it like that because this field is still required when creating a db target, so no need to make it a pointer

Copy link
Contributor Author

@chad-cwc chad-cwc Oct 11, 2023

Choose a reason for hiding this comment

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

Did you read the comment above the field? Maybe it's not clear, but I made a change in the API to allow it to be null for one specific db type. So, I thought it was appropriate to make this change. We could make it required in this SDK, though, if that makes sense. I'm not sure it does, though.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right. Sorry yeah I missed that. It's unfortunate though in Go that this would still be considered a breaking change cause now the field type has changed to a pointer type. Maybe this is evidence that we should be using pointer types everywhere just in case one day a field does become optional by the remote API. Because otherwise, we'll run into this again and cause it to break for those who expected it not to be a pointer type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Good point. We could change it back for now and change the comment to explain that the port doesn't matter for CCP-hosted databases. Then, add it to a backlog of breaking changes, which I think maybe you mentioned???

Or, of course, go forward with the breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, you could still keep it as before (no pointer type) and then in the case of GCP where it isn't required, people just won't set the field and that will end up getting serialized to:

{"remotePort":{}}

but backend should interpret that and set it to 0 the default type of the integer I think?

Copy link
Member

@ymarcus93 ymarcus93 Oct 11, 2023

Choose a reason for hiding this comment

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

So some extra bytes are sent but at least it is still backwards compatible. And then in future breaking release (batch other pending breaking changes), we can make the change you did earlier, making it a pointer type.

And then, I think we honestly should have a discussion of just making everything pointer type to prevent this from being a breaking change in the future. I'm starting to realize this is prob why the Go GitHub SDK has everything as pointer types--to prevent a situation like this where remote API makes a field optional at some point in the future.

The only annoying this is it makes using the API a little bit harder to use cause you have to make everything pointers. Luckily, though we do have a helper method to make pointers

// PtrTo returns a pointer to the provided input.
func PtrTo[T any](v T) *T {
return &v
}

But it's also cumbersome for users to have to check if pointer is non-nil before reading value. But we can remedy this with getters like we've done before on other pointer fields or autogenerate them like the Github Go SDK

Copy link
Contributor Author

@chad-cwc chad-cwc Oct 11, 2023

Choose a reason for hiding this comment

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

but backend should interpret that and set it to 0 the default type of the integer I think?

Not quite. The value for Port.Value is required by the back end, so it would error out.

I'll add a TODO as we discussed offline and will update the comment to something appropriate.

bastionzero/service/targets/dbauthconfig/dbauthconfig.go Outdated Show resolved Hide resolved
@ymarcus93 ymarcus93 merged commit 6d0c8ac into master Oct 18, 2023
6 checks passed
@ymarcus93 ymarcus93 deleted the db-auth-config branch October 18, 2023 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants