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

security: refactor gssapi_authenticator #8416

Merged

Conversation

BenPope
Copy link
Member

@BenPope BenPope commented Jan 26, 2023

Eliminate the race condition between the gssapi_authenticator shard and the thread_worker, by splitting out an impl class that only runs on the worker_thread.

Fixes: #8366

Backports Required

  • none - not a bug fix
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v22.3.x
  • v22.2.x
  • v22.1.x

UX Changes

  • none

Release Notes

  • none

Comment on lines 175 to 184
vlog(
seclog.warn,
"authenticate received after handshake complete {} bytes",
_state,
auth_bytes.size());
co_return errc::invalid_gssapi_state;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a real possibility of this happening? Would this be a candidate for a vassert?

Copy link
Member Author

@BenPope BenPope Jan 26, 2023

Choose a reason for hiding this comment

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

Is there a real possibility of this happening? Would this be a candidate for a vassert?

The connection is open to the "public", so it avoids a type of DoS.

I tend to use vassert only if the logic is wrong, rather than bad user input

Copy link
Contributor

Choose a reason for hiding this comment

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

No I understand what you mean. My question was more geared towards would the code itself be wrong if we ended up in this situation.

Copy link
Contributor

Choose a reason for hiding this comment

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

More of ignorance on my part (or lack of sleep to grasp a simple situation) but I'm trying to think how an instance of authenticator get reused.

Copy link
Member Author

@BenPope BenPope Jan 26, 2023

Choose a reason for hiding this comment

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

No I understand what you mean. My question was more geared towards would the code itself be wrong if we ended up in this situation.

I guess so, but the transition to complete is pretty simple at the moment. Any transition to failed should tear down the connection anyway.

Copy link
Member Author

@BenPope BenPope Jan 26, 2023

Choose a reason for hiding this comment

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

More of ignorance on my part (or lack of sleep to grasp a simple situation) but I'm trying to think how an instance of authenticator get reused.

The lifetime is a subset of the connection lifetime.

Copy link
Contributor

@michael-redpanda michael-redpanda left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple of questions

}
acl_principal get_principal_from_name(std::string_view source_name);

ss::sstring _primary;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be called out specifically as the _kerberos_principal? The primary is only part of the overall principal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be called out specifically as the _kerberos_principal? The primary is only part of the overall principal.

It's the primary of the Kerberos SPN. It's a bit close to _principal, I agree.

How about:

  • _krb_service_primary
  • _rp_user_principal

Copy link
Contributor

@michael-redpanda michael-redpanda Jan 26, 2023

Choose a reason for hiding this comment

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

For the redpanda won't this value be "redpanda/host@REALM"? Or is it just "redpanda"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks sorry

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks sorry

No apology needed!

@BenPope
Copy link
Member Author

BenPope commented Jan 26, 2023

CI Failure appears to be: #8179

Split off the implementation details into an impl.

Signed-off-by: Ben Pope <[email protected]>
Tidy up use of members:
* `_rules` no longer needs passing through the chain
* `_primary` and `_keytab` are now members

Signed-off-by: Ben Pope <[email protected]>
Eliminate the race condition of sharing `_state` between the
`gssapi_authenticator` shard and the `thread_worker` by
returning the current state, and assigning it to a copy.

Split the `authenticate` method between `impl` and
`gssapi_authenticator`. `fail` is now called on the correct thread.

Signed-off-by: Ben Pope <[email protected]>
Eliminate the race condition between `thread_worker` and the
`gssapi_authenticator` shard over the shared `_principal`.

Make most of the members of `impl` private.

Signed-off-by: Ben Pope <[email protected]>
@BenPope BenPope force-pushed the kerberos-refactor-gssapi-authenticator branch 2 times, most recently from 235470c to 53e1070 Compare January 26, 2023 09:48
Copy link
Contributor

@michael-redpanda michael-redpanda left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@dotnwat dotnwat left a comment

Choose a reason for hiding this comment

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

just 1 thing with the format string and argument count mismatch.

src/v/security/gssapi_authenticator.cc Show resolved Hide resolved
Comment on lines 188 to 189
_state = res.state;
co_return std::move(res.result);
Copy link
Member

Choose a reason for hiding this comment

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

curious why the state would change if the result had an error?

Copy link
Member Author

@BenPope BenPope Jan 27, 2023

Choose a reason for hiding this comment

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

I think most errors transition to state::failed, during the call to fail_impl., which allows failed() to work.

Comment on lines 181 to 183
"authenticate received after handshake complete {} bytes",
_state,
auth_bytes.size());
Copy link
Member

Choose a reason for hiding this comment

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

mismatch in fmt arguments and fmt placeholders.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Eliminate `finish`, reset `impl` when authentication is complete.

Signed-off-by: Ben Pope <[email protected]>
@BenPope BenPope requested a review from dotnwat January 27, 2023 02:18
@BenPope
Copy link
Member Author

BenPope commented Jan 27, 2023

@dotnwat dotnwat merged commit f14fbd2 into redpanda-data:dev Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

security/gssapi: Eliminate data race for _principal
3 participants