File tree Expand file tree Collapse file tree 7 files changed +20
-9
lines changed
Expand file tree Collapse file tree 7 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -327,8 +327,8 @@ impl BuildDriver for Driver {
327327 impl_build_driver ! ( push( opts) )
328328 }
329329
330- fn login ( ) -> Result < ( ) > {
331- impl_build_driver ! ( login( ) )
330+ fn login ( privileged : bool ) -> Result < ( ) > {
331+ impl_build_driver ! ( login( privileged ) )
332332 }
333333
334334 #[ cfg( feature = "prune" ) ]
Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ impl BuildDriver for BuildahDriver {
133133 Ok ( ( ) )
134134 }
135135
136- fn login ( ) -> Result < ( ) > {
136+ fn login ( _privileged : bool ) -> Result < ( ) > {
137137 trace ! ( "BuildahDriver::login()" ) ;
138138
139139 if let Some ( Credentials {
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ impl BuildDriver for DockerDriver {
221221 Ok ( ( ) )
222222 }
223223
224- fn login ( ) -> Result < ( ) > {
224+ fn login ( _privileged : bool ) -> Result < ( ) > {
225225 trace ! ( "DockerDriver::login()" ) ;
226226
227227 if let Some ( Credentials {
Original file line number Diff line number Diff line change @@ -253,7 +253,7 @@ impl BuildDriver for PodmanDriver {
253253 Ok ( ( ) )
254254 }
255255
256- fn login ( ) -> Result < ( ) > {
256+ fn login ( privileged : bool ) -> Result < ( ) > {
257257 trace ! ( "PodmanDriver::login()" ) ;
258258
259259 if let Some ( Credentials {
@@ -262,11 +262,22 @@ impl BuildDriver for PodmanDriver {
262262 password,
263263 } ) = Credentials :: get ( )
264264 {
265+ let use_sudo = privileged && !running_as_root ( ) ;
265266 let output = pipe ! (
266267 stdin = password;
267268 {
268269 let c = cmd!(
269- "podman" ,
270+ if use_sudo {
271+ "sudo"
272+ } else {
273+ "podman"
274+ } ,
275+ if use_sudo && has_env_var( SUDO_ASKPASS ) => [
276+ "-A" ,
277+ "-p" ,
278+ SUDO_PROMPT ,
279+ ] ,
280+ if use_sudo => "podman" ,
270281 "login" ,
271282 "-u" ,
272283 username,
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ pub trait BuildDriver: PrivateDriver {
106106 ///
107107 /// # Errors
108108 /// Will error if login fails.
109- fn login ( ) -> Result < ( ) > ;
109+ fn login ( privileged : bool ) -> Result < ( ) > ;
110110
111111 /// Runs prune commands for the driver.
112112 ///
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ impl BlueBuildCommand for BuildCommand {
161161 if self . push {
162162 blue_build_utils:: check_command_exists ( "cosign" ) ?;
163163 Driver :: check_signing_files ( & CheckKeyPairOpts :: builder ( ) . dir ( Path :: new ( "." ) ) . build ( ) ) ?;
164- Driver :: login ( ) ?;
164+ Driver :: login ( self . rechunk ) ?;
165165 Driver :: signing_login ( ) ?;
166166 }
167167
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ impl BlueBuildCommand for LoginCommand {
4545 . build ( ) ,
4646 ) ;
4747
48- Driver :: login ( ) ?;
48+ Driver :: login ( false ) ?;
4949 Driver :: signing_login ( ) ?;
5050
5151 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments