MCPcopy Index your code
hub / github.com/bytebase/bytebase / shouldSwitchUser

Function shouldSwitchUser

backend/resources/postgres/postgres.go:156–181  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

154}
155
156func shouldSwitchUser() (uint32, uint32, bool, error) {
157 sameUser := true
158 bytebaseUser, err := user.Current()
159 if err != nil {
160 return 0, 0, true, errors.Wrap(err, "failed to get current user")
161 }
162 // If user runs Bytebase as root user, we will attempt to run as user `bytebase`.
163 // https://www.postgresql.org/docs/14/app-initdb.html
164 if bytebaseUser.Username == "root" {
165 bytebaseUser, err = user.Lookup("bytebase")
166 if err != nil {
167 return 0, 0, false, errors.Errorf("please run Bytebase as non-root user. You can use the following command to create a dedicated \"bytebase\" user to run the application: addgroup --gid 113 --system bytebase && adduser --uid 113 --system bytebase && adduser bytebase bytebase")
168 }
169 sameUser = false
170 }
171
172 uid, err := strconv.ParseUint(bytebaseUser.Uid, 10, 32)
173 if err != nil {
174 return 0, 0, false, err
175 }
176 gid, err := strconv.ParseUint(bytebaseUser.Gid, 10, 32)
177 if err != nil {
178 return 0, 0, false, err
179 }
180 return uint32(uid), uint32(gid), sameUser, nil
181}

Callers 3

startFunction · 0.85
stopFunction · 0.85
initDBFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected