1 |
Momesso Andrea <momesso.andrea@×××××.com> wrote: |
2 |
|
3 |
> |
4 |
> Quoting Andrea Conti <alyf@××××.net>: |
5 |
> |
6 |
> > On 07/10/2010 18:45, Momesso Andrea wrote: |
7 |
> > |
8 |
> >> Setting up a public key, would do the job, but then, all the connections |
9 |
> >> between the servers would be passwordless, so if server A gets |
10 |
> >> compromised, also server B is screwed. |
11 |
> > |
12 |
> > Well, not really... public key authentication works on a per-user basis, |
13 |
> > so all you get is that some user with a specific key can log in as some |
14 |
> > other user of B without typing a password. |
15 |
> > |
16 |
> > Of course, if you authorize a given key for logging in as root@B, then |
17 |
> > what you said is true. But that is a problem with the specific setup. |
18 |
> > |
19 |
> >> Is there a way to allow only one single command from a single cronjob to |
20 |
> >> operate passwordless, while keeping all the other connections secured by |
21 |
> >> a password? |
22 |
> > |
23 |
> > You can't do that on a per-command basis. You'd be trying to control the |
24 |
> > authentication method accepted by sshd on B according to which command |
25 |
> > is run on A -- something sshd on B knows nothing about. |
26 |
> > |
27 |
> > I would try the following way: |
28 |
> > |
29 |
> > - Set up an unprivileged user on B -- let's call it foo -- which can |
30 |
> > only write to its own home directory, /home/foo. |
31 |
> > |
32 |
> > - add the public key you will be using (*) to foo@B's authorized_keys |
33 |
> > file. You should set the key's options to |
34 |
> > 'pattern="<address_of_A>",no-pty,command="/usr/bin/scp -t -- /home/foo"' |
35 |
> > (man sshd for details). |
36 |
> > |
37 |
> > - chattr +i /home/foo/.ssh/authorized_keys, so that the file can only be |
38 |
> > changed by a superuser (you can't just chown the file to root as sshd is |
39 |
> > quite anal about the permissions of the authorized_keys file) |
40 |
> > |
41 |
> > Now your cron job on A can do "scp <file> foo@B:/home/foo" without the |
42 |
> > need for entering a password; you just have to set up another cron job |
43 |
> > on B that picks up the file from /home/foo and puts it where it should |
44 |
> > go with the correct permissions, possibly after doing a sanity check on |
45 |
> > its contents. |
46 |
> > |
47 |
> > If you use something else than scp, (e.g. rsync) you should also adjust |
48 |
> > the command option in the key options above. |
49 |
> > Note that the option refers to what is run on B, not on A. Also, it is |
50 |
> > *not* an authorization directive à la /etc/sudoers (i.e., it does not |
51 |
> > specify what commands the user is allowed to run): it simply overwrites |
52 |
> > whichever command is requested by the client side of the ssh connection, |
53 |
> > so that, for example, the client cannot request a shell or do "cat |
54 |
> > <somefile>". |
55 |
> > |
56 |
> > (*) You can either use the key of the user running the cron job on A, or |
57 |
> > generate a separate key which is only used for the copy operation. In |
58 |
> > this case, you will need to tell scp the location of the private key |
59 |
> > file with the -i option. |
60 |
> > |
61 |
> > HTH, |
62 |
> > andrea |
63 |
> > |
64 |
> > |
65 |
> |
66 |
> Thank you all for your fast replies, I think I'll use all of your suggestions: |
67 |
> |
68 |
> -create an unprivilegied user with no shell access as Stroller and |
69 |
> Andrea suggested |
70 |
> |
71 |
> -I'll setup a passwordless key for this user, only limited to a single |
72 |
> command, as Willie |
73 |
> suggested |
74 |
> |
75 |
> This sounds pretty sane to me. |
76 |
I think for ssh to work the user needs a valid shell, not nologin, so |
77 |
you can't do both of those suggestions.] |
78 |
|
79 |
-- |
80 |
Your life is like a penny. You're going to lose it. The question is: |
81 |
How do |
82 |
you spend it? |
83 |
|
84 |
John Covici |
85 |
covici@××××××××××.com |