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

Implementation of peer credentials for Unix sockets #75148

Merged
merged 10 commits into from
Sep 15, 2020

Conversation

joechrisellis
Copy link
Contributor

The code in ucred.rs is based on the work done in PR 13 in the tokio-uds repository on GitHub.

This commit is effectively a port to the stdlib, so credit to Martin Habovštiak (@Kixunil) and contributors for the meat of this work. 🥇

Happy to make changes as needed. 🙂

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 4, 2020
@Kixunil
Copy link
Contributor

Kixunil commented Aug 4, 2020

Awesome, thanks for the credit and for your additional work on getting this to std! Looking forward to another opportunity when I can use it. :)

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct UCred {
pub uid: uid_t,
pub gid: gid_t,
Copy link
Contributor

Choose a reason for hiding this comment

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

something_t types are not used in std often (at all?), is this a good idea?

Personally I'd love seeing use of newtypes as done in nix, but not sure if that should go to std.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a quick grep of the codebase and I can see a few places where these are used... I'll leave it as it is for now! If you would strongly like this to change feel free to follow up. 🙂

let mut ucred_size = ucred_size as u32;

unsafe {
let mut ucred: ucred = MaybeUninit::uninit().assume_init();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think assume_init is correct here. I believe raw ptr should be obtained from MaybeUninit, then passed to getsockopt and only after it succeeds calling assume_init

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done -- I opted against using MemUninit in the end, it doesn't seem necessary.

&mut ucred_size,
);

if ret == 0 && ucred_size as usize == mem::size_of::<ucred>() {

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. 😄

pub fn peer_cred(socket: &UnixStream) -> io::Result<UCred> {
unsafe {
// Create `cred` and attempt to populate it.
let mut cred: UCred = MaybeUninit::uninit().assume_init();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue with assume_init 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.

See above. 😄

assert!(ucred_size <= u32::max_value() as usize);

let mut ucred_size = ucred_size as u32;
let mut ucred: ucred = ucred { pid: 1, uid: 1, gid: 1 };
Copy link
Contributor

Choose a reason for hiding this comment

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

Oooh, nice defensive programming using 1 instead of 0! ❤️

Comment on lines 14 to 26
pub struct UCred {
pub uid: uid_t,
pub gid: gid_t,
}

Choose a reason for hiding this comment

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

Out of curiosity - why not return the process ID too, since that's returned by the syscall?

Copy link
Contributor

Choose a reason for hiding this comment

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

PID is only available on Linux, it's not available on BSD.

Choose a reason for hiding this comment

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

Is it possible to include it (conditionally) on Linux?

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically yes. It'd require change of the API due to coding standard in std (mainly using extension traits for additional platforms, IDK why such standard exists).

Choose a reason for hiding this comment

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

Ah, fair enough, I was hoping for a small, clean change :) nevermind then

Copy link
Member

@Amanieu Amanieu Sep 6, 2020

Choose a reason for hiding this comment

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

Could we make the PID an Option<pid_t>? A quick search reveals that it is in fact supported on quite a few BSD platforms (e.g. FreeBSD).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done -- however, my Google-fu is failing me here. I can't find anything about retrieving the PID from a domain socket on FreeBSD. The closest I can find is getpeereid which accepts a UID and GID only. So at the moment, the optional PID is set to None for BSD, and Some(pid) on Linux.

Copy link
Member

Choose a reason for hiding this comment

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

It seems to have been added relatively recently: https://svnweb.freebsd.org/base?view=revision&revision=348419

joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Aug 6, 2020
This authenticator uses Unix peer credentials for authentication. Unix
peer credentials provide direct access to the (effective) uid/gid on the
other end of a domain socket connect, without cooperation between the
endpoints. This means that we can determine the uid/gid of the
connecting process, and therefore infer the username of the user that
owns said process.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- determine the username of the owner of the connecting process based on
  the uid.
- creates an `ApplicationName` based on the username.

Note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Aug 6, 2020
This authenticator uses Unix peer credentials for authentication. Unix
peer credentials provide direct access to the (effective) uid/gid on the
other end of a domain socket connect, without cooperation between the
endpoints. This means that we can determine the uid/gid of the
connecting process, and therefore infer the username of the user that
owns said process.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- determine the username of the owner of the connecting process based on
  the uid.
- creates an `ApplicationName` based on the username.

Note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Aug 6, 2020
This authenticator uses Unix peer credentials for authentication. Unix
peer credentials provide direct access to the (effective) uid/gid on the
other end of a domain socket connect, without cooperation between the
endpoints. This means that we can determine the uid/gid of the
connecting process, and therefore infer the username of the user that
owns said process.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`uds-authenticator`.

Note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Aug 11, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
@joechrisellis
Copy link
Contributor Author

Hi all! Just gently pinging this PR for review. 🙂

@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 4, 2020
@Dylan-DPC-zz
Copy link

@joechrisellis thanks but would advise not to ping for reviewers. The triage team currently uses the last time a PR was updated as a parameter to filter which pull requests need to be checked, which means posting a message that doesn't contribute to the PR can delay the process further. In future, if anyone reading this wants to grab attention on a PR that's sitting idle for a while, you can contact the triage-team on zulip and we will take care of it

@Dylan-DPC-zz
Copy link

r? @Amanieu

pub uid: uid_t,
pub gid: gid_t,
// pid field is an option because it is not supported on some platforms.
pub pid: Option<pid_t>,
Copy link
Member

Choose a reason for hiding this comment

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

Could we get doc comments for each of the public fields? In particular the Option<pid_t> should be explained in the docs.

@Amanieu
Copy link
Member

Amanieu commented Sep 8, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Sep 8, 2020

📌 Commit 80860181445f14e6f305c687b2056f11ebc4629a has been approved by Amanieu

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 8, 2020
@bors
Copy link
Contributor

bors commented Sep 15, 2020

📌 Commit 68ff495 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2020
@bors
Copy link
Contributor

bors commented Sep 15, 2020

⌛ Testing commit 68ff495 with merge a874956...

@bors
Copy link
Contributor

bors commented Sep 15, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: Amanieu
Pushing a874956 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 15, 2020
@bors bors merged commit a874956 into rust-lang:master Sep 15, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 15, 2020
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 16, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 17, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 17, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 21, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 21, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 21, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 21, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 21, 2020
This authenticator uses peer credentials for authentication. The
specific type of peer credentials in mind at the moment are Unix peer
credentials, but this can be extended in the future.

Unix peer credentials provide direct access to the (effective) uid/gid
on the other end of a domain socket connect, without cooperation between
the endpoints. This means that we can trivially determine the uid/gid of
the connecting process, which we can then use for authentication.

This authenticator:

- grabs the (uid, gid) pair of the connecting process.
- grabs the self-declared uid sent in the authentication request.
- verifies that authentication is successful by checking that the
  self-declared uid in the authentication request is equal to the actual
  uid from the peer credentials.
- if authentication was successful, creates an `ApplicationName` based
  on the uid.

The authenticator is hidden behind the Cargo feature
`peer-credentials-authenticator`.

Note that gid is currently unused by the authenticator.

Also note that this patch depends on the following PR being merged:

    rust-lang/rust#75148

At the time of writing, this PR is currently under review and is not
merged into the Rust stdlib. This patch therefore will not build with
the current a stable/nightly compiler.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
joechrisellis pushed a commit to joechrisellis/parsec that referenced this pull request Sep 21, 2020
The code introduced in this patch has been cherry-picked from the
following PR:

    rust-lang/rust#75148

At the time of writing (16/09/20), this patch is in the nightly Rust
channel. To avoid needing to use the nightly compiler to build Parsec,
this patch includes the change from the standard library to allow us to
use this feature 'early'.

Once the feature hits the stable branch, it should be safe to revert
this commit with `git revert`.

Signed-off-by: Joe Ellis <joe.ellis@arm.com>
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 9, 2020
…s, r=Amanieu

ext/ucred: Support PID in peer creds on macOS

This is a follow-up to rust-lang#75148 (RFC: rust-lang#42839).

The original PR used `getpeereid` on macOS and the BSDs, since they don't (generally) support the `SO_PEERCRED` mechanism that Linux supplies.

This PR splits the macOS/iOS implementation of `peer_cred()` from that of the BSDs, since macOS supplies the `LOCAL_PEERPID` sockopt as a source of the missing PID. It also adds a `cfg`-gated tests that ensures that platforms with support for PIDs in `UCred` have the expected data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet