Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
0642d9b
Add certificate renewal bot
timothyb89 Dec 10, 2021
278373b
Cert bot refactoring pass
timothyb89 Jan 21, 2022
3cb5f41
Do not pass through `renewable` flag when role requests are set
timothyb89 Jan 26, 2022
65997a6
Various tbot UX improvements; render SSH config
timothyb89 Jan 26, 2022
ff58ccf
Add stubs for tbot init and watch commands
timothyb89 Jan 26, 2022
75ee80b
Add gRPC endpoints for managing bots
timothyb89 Jan 27, 2022
65b4f91
Fix outdated destination flag in example tbot command
timothyb89 Feb 2, 2022
fced606
Bugfix pass for demo
timothyb89 Feb 2, 2022
e8b3b0f
Address first wave of review feedback
timothyb89 Feb 4, 2022
773a4ef
Add doc comments for bot.go functions
timothyb89 Feb 4, 2022
34ae6a6
Return the token TTL from CreateBot
timothyb89 Feb 4, 2022
9c5ca57
Split initial user cert issuance from `generateUserCerts()`
timothyb89 Feb 8, 2022
17a1c77
Set bot traits to silence log messages
timothyb89 Feb 8, 2022
bd3152b
tbot log message consistency pass
timothyb89 Feb 8, 2022
d7c49e7
Implement `tbot init` subcommand
timothyb89 Feb 10, 2022
12942dd
Resolve lints
timothyb89 Feb 10, 2022
8cd83c7
Add config tests
timothyb89 Feb 11, 2022
28bab88
Remove CreateBotJoinToken endpoint
timothyb89 Feb 11, 2022
5a71864
Merge remote-tracking branch 'origin/master' into timothyb89/tbot
timothyb89 Feb 11, 2022
d800382
Create a fresh private key for every impersonated identity renewal
timothyb89 Feb 15, 2022
cefe734
Hide `config` subcommand
timothyb89 Feb 15, 2022
5003459
Rename bot label prefix to `teleport.internal/`
timothyb89 Feb 15, 2022
0b7e7e5
Merge branch 'timothyb89/tbot' into timothyb89/tbot-init
timothyb89 Feb 15, 2022
f725b62
Use types.NewRole() to create bot roles
timothyb89 Feb 16, 2022
4a3a417
Clean up error handling in custom YAML unmarshallers
timothyb89 Feb 16, 2022
28f930b
Fetch proxy host via gRPC Ping() instead of GetProxies()
timothyb89 Feb 16, 2022
00e29b5
Merge remote-tracking branch 'origin/master' into timothyb89/tbot
timothyb89 Feb 17, 2022
a7529b9
Update lib/auth/bot.go
timothyb89 Feb 18, 2022
b1bbcb8
Fix some review comments
timothyb89 Feb 18, 2022
004b25c
Add renewable certificate generation checks (#10098)
timothyb89 Feb 18, 2022
c3be5d6
Address another batch of review feedback
timothyb89 Feb 18, 2022
f004e10
Addres another batch of review feedback
timothyb89 Feb 18, 2022
77c0803
Merge remote-tracking branch 'origin/master' into timothyb89/tbot
timothyb89 Feb 18, 2022
1f946f9
Fix lint
timothyb89 Feb 18, 2022
587974d
Add missing doc comments to SaveIdentity / LoadIdentity
timothyb89 Feb 18, 2022
bd5f514
Merge remote-tracking branch 'origin/master' into timothyb89/tbot
timothyb89 Feb 18, 2022
01546ec
Remove pam tag from tbot build
timothyb89 Feb 18, 2022
bf1cf3a
Update note about bot lock deletion
timothyb89 Feb 18, 2022
c65c56a
Another pass of review feedback
timothyb89 Feb 19, 2022
0300f52
Merge remote-tracking branch 'origin/master' into timothyb89/tbot
timothyb89 Feb 19, 2022
73b7ba2
Merge branch 'timothyb89/tbot' into timothyb89/tbot-init
timothyb89 Feb 22, 2022
0ad110e
Merge remote-tracking branch 'origin/master' into timothyb89/tbot-init
timothyb89 Feb 22, 2022
cf6406f
Remove ModeHint
timothyb89 Feb 23, 2022
0f78580
Rename Identity.Cert and Identity.XCert
timothyb89 Feb 24, 2022
3e0a05f
Add `symlinks` flag to tbot config
timothyb89 Feb 24, 2022
3da96dd
Add mostly-working secure implementation of botfs.Create/Write
timothyb89 Feb 24, 2022
f94f724
Merge remote-tracking branch 'origin/master' into timothyb89/tbot-init
timothyb89 Mar 1, 2022
5ddfd71
Add configurable ACL modes and verify ACL support in tbot init
timothyb89 Mar 1, 2022
37400dc
Initialize destinations at startup and test before renewal
timothyb89 Mar 1, 2022
c9fb533
Hide watch for now
timothyb89 Mar 1, 2022
4b2fa72
Issue a new identity if a token change is detected
timothyb89 Mar 1, 2022
40f6d0b
Warn if identity appears to be expired on startup
timothyb89 Mar 1, 2022
9893602
Fully implement ACL Verify and Configure
timothyb89 Mar 2, 2022
048b524
Make `tbot init` work without a config file
timothyb89 Mar 2, 2022
25017b4
Show init instructions in tctl bots add
timothyb89 Mar 3, 2022
7f25b5a
Clear some TODOs and rephrase tctl help
timothyb89 Mar 3, 2022
73bed1a
Fix typo
timothyb89 Mar 3, 2022
b2460a4
Merge remote-tracking branch 'origin/master' into timothyb89/tbot-init
timothyb89 Mar 3, 2022
1276661
Fix token hash detection bug
timothyb89 Mar 3, 2022
202a97d
Actually read and write certs with symlink enforcement
timothyb89 Mar 3, 2022
b114926
Add workaround for OpenSSH permissions check with ACLs
timothyb89 Mar 5, 2022
24d066f
Fix lints
timothyb89 Mar 7, 2022
6b9223f
Fix an improper directory chmod to 0600 if ACL test fails
timothyb89 Mar 7, 2022
8a8d656
First pass of tbot init unit tests
timothyb89 Mar 7, 2022
3d55e48
Add symlink tests and fix bug with resolving the default owner
timothyb89 Mar 7, 2022
5ac9aa2
Fix err misuse
timothyb89 Mar 7, 2022
7a96daa
Fix an ACL error if the bot or reader user is the owner.
timothyb89 Mar 7, 2022
126162d
Merge remote-tracking branch 'origin/master' into timothyb89/tbot-init
timothyb89 Mar 7, 2022
1994858
Fix typo
timothyb89 Mar 7, 2022
9bb139e
Fix missing error case in VerifyACL causing unreadable directories
timothyb89 Mar 8, 2022
ca974b8
Address review feedback
timothyb89 Mar 8, 2022
8855518
Apply suggestions from code review
timothyb89 Mar 8, 2022
38c9fcb
Address review feedback
timothyb89 Mar 8, 2022
af1908a
Fix lint error
timothyb89 Mar 9, 2022
d9f8ed1
Merge branch 'master' into timothyb89/tbot-init
timothyb89 Mar 10, 2022
26f8fc9
Fix imports in fs_other
timothyb89 Mar 10, 2022
19dc449
Fix possible nil pointer deref if storage is unset
timothyb89 Mar 10, 2022
33afc77
Use the bot user as default owner
timothyb89 Mar 10, 2022
42aee8a
Apply suggestions from code review
timothyb89 Mar 10, 2022
e416fdb
Code review fixes
timothyb89 Mar 10, 2022
8bb8a5c
Merge branch 'master' into timothyb89/tbot-init
timothyb89 Mar 10, 2022
e76777c
Merge branch 'master' into timothyb89/tbot-init
timothyb89 Mar 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ require (
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.9.5 // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531 h1:hgVxRoDDPtQE68PT4LFvNlPz2nBKd3OMlGKIQ69OmR4=
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531/go.mod h1:fqTUQpVYBvhCNIsMXGl2GE9q6z94DIP6NtFKXCSTVbg=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func formatCertError(err error) string {
}

const (
// Bold is an escape code to format as bold or increased intensity
Bold = 1
// Red is an escape code for red terminal color
Red = 31
// Yellow is an escape code for yellow terminal color
Expand Down
156 changes: 156 additions & 0 deletions tool/tbot/botfs/botfs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
Copyright 2022 Gravitational, Inc.

Licensed 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

http://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.
*/

package botfs

import (
"io/fs"
"os"
"os/user"
"runtime"
"strconv"
"syscall"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
)

var log = logrus.WithFields(logrus.Fields{
trace.Component: teleport.ComponentTBot,
})

// SymlinksMode is an enum type listing various symlink behavior modes.
type SymlinksMode string

const (
// SymlinksInsecure does allow resolving symlink paths and does not issue
// any symlink-related warnings.
SymlinksInsecure SymlinksMode = "insecure"

// SymlinksTrySecure attempts to write files securely and avoid symlink
// attacks, but falls back with a warning if the necessary OS / kernel
// support is missing.
SymlinksTrySecure SymlinksMode = "try-secure"

// SymlinksSecure attempts to write files securely and fails with an error
// if the operation fails. This should be the default on systems where we
// expect it to be supported.
SymlinksSecure SymlinksMode = "secure"
)

// ACLMode is an enum type listing various ACL behavior modes.
type ACLMode string

const (
// ACLOff disables ACLs
ACLOff ACLMode = "off"

// ACLTry attempts to use ACLs but falls back to no ACLs with a warning if
// unavailable.
ACLTry ACLMode = "try"

// ACLRequired enables ACL support and fails if ACLs are unavailable.
ACLRequired ACLMode = "required"
)

const (
// DefaultMode is the preferred permissions mode for bot files.
DefaultMode fs.FileMode = 0600

// DefaultDirMode is the preferred permissions mode for bot directories.
// Directories need the execute bit set for most operations on their
// contents to succeed.
DefaultDirMode fs.FileMode = 0700
)

// ACLOptions contains parameters needed to configure ACLs
type ACLOptions struct {
// BotUser is the bot user that should have write access to this entry
BotUser *user.User

// ReaderUser is the user that should have read access to the file. This
// may be nil if the reader user is not known.
ReaderUser *user.User
}

// openStandard attempts to open the given path for writing with O_CREATE set.
func openStandard(path string) (*os.File, error) {
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, DefaultMode)
if err != nil {
return nil, trace.ConvertSystemError(err)
}

return file, nil
}

// createStandard creates an empty file or directory at the given path without
// attempting to prevent symlink attacks.
func createStandard(path string, isDir bool) error {
if isDir {
if err := os.Mkdir(path, DefaultDirMode); err != nil {
return trace.ConvertSystemError(err)
}

return nil
}

f, err := openStandard(path)
if err != nil {
return trace.Wrap(err)
}

if err := f.Close(); err != nil {
log.Warnf("Failed to close file at %q: %+v", path, err)
}

return nil
}

// GetOwner attempts to retrieve the owner of the given file. This is not
// supported on all platforms and will return a trace.NotImplemented in that
// case.
func GetOwner(fileInfo fs.FileInfo) (*user.User, error) {
info, ok := fileInfo.Sys().(*syscall.Stat_t)
if !ok {
return nil, trace.NotImplemented("Cannot verify file ownership on this platform.")
}

user, err := user.LookupId(strconv.Itoa(int(info.Uid)))
if err != nil {
return nil, trace.Wrap(err)
}

return user, nil
}

// IsOwnedBy checks that the file at the given path is owned by the given user.
// Returns a trace.NotImplemented() on unsupported platforms.
func IsOwnedBy(fileInfo fs.FileInfo, user *user.User) (bool, error) {
if runtime.GOOS == constants.WindowsOS {
// no-op on windows
return false, trace.NotImplemented("Cannot verify file ownership on this platform.")
}

info, ok := fileInfo.Sys().(*syscall.Stat_t)
if !ok {
return false, trace.NotImplemented("Cannot verify file ownership on this platform.")
}

// Our files are 0600, so don't bother checking gid.
return strconv.Itoa(int(info.Uid)) == user.Uid, nil
}
Loading