Coder Social home page Coder Social logo

cloudposse-archives / sudosh Goto Github PK

View Code? Open in Web Editor NEW
93.0 14.0 15.0 25 KB

Shell wrapper to run a login shell with `sudo` as the current user for the purpose of audit logging

Home Page: https://cloudposse.com/accelerate

License: Apache License 2.0

Makefile 14.73% Go 85.27%
sudo shell wrapper sudosh audit-logs ssh bash zsh sudoreplay

sudosh's Introduction

README Header

Cloud Posse

Sudo Shell Build Status Latest Release GitHub Stars Average time to resolve an issue Percentage of issues still open Slack Community

Sudo Shell is a wrapper to run a login shell with sudo for the purpose of session audit logging.


This project is part of our comprehensive "SweetOps" approach towards DevOps.

It's 100% Open Source and licensed under the APACHE2.

Introduction

The sudo command provides built-in session logging. Combined with sudoreplay it provides an easy way to review session logs on a bastion host. When used as a system login shell, it will force session logging.

Another common pattern is to use the OpenSSH ForceCommand directive in sshd_config combined with the script command to log sessions. This is ineffective because the user can easily bypass it.
Using sudosh provides a more secure alternative that cannot be bypassed since it does not depend on ForceCommand.

Usage

Here's how to use it in 3 easy steps. Checkout the precompiled releases if you don't want to build it yourself...:

  1. Enable sudo logging. Edit /etc/sudoers.d/sudosh:
Defaults log_output
Defaults!/usr/bin/sudoreplay !log_output
Defaults!/sbin/reboot !log_output
  1. Add this command to /etc/shells:
/usr/bin/sudosh

Tip: to prevent users from using other shells to login, remove those shells from /etc/shells.

  1. Update the user foobar to use the sudosh shell.
chsh -s /usr/bin/sudosh foobar
echo 'foobar ALL=(foobar) ALL' > /etc/sudoers.d/sudosh-foobar

NOTE: filenames in sudoers.d cannot contain the . character

Help

Got a question? We got answers.

File a GitHub issue, send us an email or join our Slack Community.

README Commercial Support

DevOps Accelerator for Startups

We are a DevOps Accelerator. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.

Learn More

Work directly with our team of DevOps experts via email, slack, and video conferencing.

We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet.

  • Reference Architecture. You'll get everything you need from the ground up built using 100% infrastructure as code.
  • Release Engineering. You'll have end-to-end CI/CD with unlimited staging environments.
  • Site Reliability Engineering. You'll have total visibility into your apps and microservices.
  • Security Baseline. You'll have built-in governance with accountability and audit logs for all changes.
  • GitOps. You'll be able to operate your infrastructure via Pull Requests.
  • Training. You'll receive hands-on training so your team can operate what we build.
  • Questions. You'll have a direct line of communication between our teams via a Shared Slack channel.
  • Troubleshooting. You'll get help to triage when things aren't working.
  • Code Reviews. You'll receive constructive feedback on Pull Requests.
  • Bug Fixes. We'll rapidly work with you to fix any bugs in our projects.

Slack Community

Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.

Discourse Forums

Participate in our Discourse Forums. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account.

Newsletter

Sign up for our newsletter that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.

Office Hours

Join us every Wednesday via Zoom for our weekly "Lunch & Learn" sessions. It's FREE for everyone!

zoom

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

If you are interested in being a contributor and want to get involved in developing this project or help out with our other projects, we would love to hear from you! Shoot us an email.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

Copyright

Copyright © 2017-2020 Cloud Posse, LLC

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Trademarks

All other trademarks referenced herein are the property of their respective owners.

About

This project is maintained and funded by Cloud Posse, LLC. Like it? Please let us know by leaving a testimonial!

Cloud Posse

We're a DevOps Professional Services company based in Los Angeles, CA. We ❤️ Open Source Software.

We offer paid support on all of our projects.

Check out our other projects, follow us on twitter, apply for a job, or hire us to help with your cloud strategy and implementation.

Contributors

Erik Osterman
Erik Osterman

README Footer Beacon

sudosh's People

Contributors

fehersanyi-bitrise avatar osterman avatar solairerove avatar timp87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sudosh's Issues

FreeBSD Build Fails

I’m trying to build sudosh under FreeBSD (11.0-REL). Before contemplating any external builds, I routinely install the following packages (which many other github ports rely on for builds):

pkg install -y autoconf automake m4

I’m getting the following error during make of sudosh:

make: "/usr/share/mk/sys.mk" line 424: Cannot open /etc/make.conf
make: Fatal errors encountered -- cannot continue

The stock FreeBSD does have sys.mk files in various places:

% locate sys.mk
- /usr/share/mk/bsd.sys.mk
- /usr/share/mk/meta.sys.mk
- /usr/share/mk/sys.mk

Can someone help me with the make? The Makefile doesn’t reference sys.mk - the reference seems to be coming from somewhere else (perhaps one of the nasty curl auto-includes).

Also, please note that the default installation (per the README.mc) expects to see:

  • /etc/sudoers.d/sudosh
  • /usr/bin/sudoreplay

… and the politically correct place for these on FreeBSD is:

  • /usr/local/etc/sudosh.conf (if you want a config independent of sudo's config)
  • /usr/local/etc/sudoers (if you want to share sudo's config)
  • /usr/local/bin/sudoreplay (default baseline installation location)

In addition, I'm curious what the default log location is for this binary.

Guidance for use with ssh ProxyCommand

Hi there,

I'm trying to use this with my own Bastion host (unfortunately I can't use cloudposse/bastion). I want to be able to use the ProxyCommand so that I can pass my private key through to the target host, however if I do this, the sudo logs are encrypted.

I'm using the following ssh config:

HOST remote-server
  IdentityFile ~/key.pem
  ForwardAgent yes
  ProxyCommand ssh ec2-user@bastion-ip nc %h %p

I've also tried the ProxyCommand with -W but this seems to require turning on AllowTcpForwarding and nothing is captured in the sudo logs.

Cheers

Update to use`README.yaml`

what

  • Convert README.md to README.yaml

why

  • So we can better integrate with all of our other repos
  • Consistency

Project name

I'm not asking you to do anything with this but I suppose you should know (if you didn't) that sudosh was already used by some projects earlier.
The original project was:
https://sourceforge.net/projects/sudosh/
Looks like it was picked up by commercial company and some forks established then:
https://github.com/squash/sudosh2
https://github.com/asquelt/eas

I'm just letting you know. Owners may ask you to change your project name eventually.
Well, a new name could be simple gosudosh ;)

Regression in security caveats

First, I like how you do the markdown generation from YaML. I need to look into using that :)

The reason I opened this is because it seems the documentation added as a result of the discussion here seems to have been lost at some point- there is no mention of it any longer. Maybe it was lost when the switch to YaML was made? Or were those caveats (and respective mitigations) intentionally removed?

I just wanted to make sure if the removal was unintentional that it come to your attention. Personally I still think think use of RequestTTY=no / -T by SSH clients is a major blindspot for sysadmins- a subset of which are certainly users of sudosh. Because there is a mitigation (not just "best-effort") I feel it's important to document

I understand that it can be said to SSH and not request a TTY is simply deliberate bad behavior in a sanctioned environment and that users at some point must be trusted to follow procedures- but it's actually very easy to do this unintentionally, as mentioned in the original issue, using ssh host bash- since that implicitly sets the ssh flag to not request a tty.

It's also generally (and unfortunately, in this case) the modus operandi of attackers (red-teams or "real" attackers) to use SSH in this way, simply because it doesn't create an entry in UTMP/WTMP. An attacker might subvert sudosh completely by dumb luck if the sysadmin wasn't aware of the issue and did not apply the necessary mitigation

Using the mitigation recommended in the previous issue (essentially requiring TTY allocation on the server-side) will break scp - but it will not have any adverse effect on sftp since (as you probably know, but many users may not) SFTP uses a channel type different than those for SSH commands

FWIW, scp is (I believe) officially on its way to deprecation, both for security reasons and for overall "it's a hack long overdue to die" reasons- see here and here

Thanks for your work on this project, it's a really effective open-source solution for a very real and common problem- and it's easy to use

EDIT: I'm on mobile, so maybe the caveats are somewhere I'm not seeing. If that's the case, my apologies

Clarification on how to securely utilize sudosh

Hello devs,

I wanted to just point out something that you may know, but that users may not. For complete and secure logging, it is not sufficient to simply set the user shell to sudosh. You must either use ForceCommand or a bastion that disallows users from invoking SSH directly. Otherwise you have the issue of the following session on somehost going (partially) unaudited:

$ ssh user@somehost bash

In this case, even though the user's shell may be set to sudosh, the only things that will be audited are the initial invocation of bash and the stdout/stderr of the bash shell that was invoked. The stdin of the bash session will not be logged, based on my (limited) testing. Apologies if I made a mistake in testing, but this is what it looks like to me

References to ForceCommand and a bastion host are made in the documentation, but I feel that the documentation doesn't do a great job in pointing out this "bypass" (albeit partial) of session logging.

Maybe I am just not reading the README carefully enough, but it seems like this specific case should be called out as a common pitfall as I think a lot of system administrators overlook things like this, unless they have experience in doing basic subversion testing

Feel free to close this with comments if you feel that this is common knowledge and not a risk. Alternately, maybe you can update the README, or invite a PR to improve the README. I just wanted to make sure there was awareness around this common mistake that syadmins tend to make. I've seen this sort of mistake in several environments, not with sudosh, but with similar tools

Thanks

Sudosh + requiretty = no more scp/rsync

Hi!

I recently implemented sudosh on a couple of CentOS boxes with the requiretty setting in sudoers. However, this breaks scp and rsync. Is there a way to make those work again? I feel there has to be a combination of sudo rules that allow it.

Anyone any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.