![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||||
| |||||
|
|
The following bug has been logged online: |
|
Bug reference: 1830 Logged by: Bernard Email address: bht (AT) actrix (DOT) gen.nz PostgreSQL version: 8.0.3 Operating system: Linux RedHat 9 Description: Non-super-user must be able to copy from a file Details: On the attempt to bulk load a table from a file that is owned by the non-superuser current database user, the following error message is printed: "must be superuser to COPY to or from a file" What is the reason for this limitation? |
|
It can't justifiably be for security reasons because if a web application such as tomcat requires to bulk load tables automatically on a regular basis then one would be forced to let the web application connect as superuser, which is very bad for security. |
|
In MySQL bulk loading works for all users. |
|
We need a Postgresql solution. We have a web application where both MySQL and Postresql are supported. With Postgresql, the application would have to connect as user postgres. We have to explain this security risk to our clients very clearly. ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
#3
| |||
| |||
|
|
On Wed, Aug 17, 2005 at 09:22:16 +0100, Bernard <bht (AT) actrix (DOT) gen.nz> wrote: =20 The following bug has been logged online: This isn't a bug and you really should have asked this question on another list. I am moving the discussion over to the general list. =20 Bug reference: 1830 Logged by: Bernard Email address: bht (AT) actrix (DOT) gen.nz PostgreSQL version: 8.0.3 Operating system: Linux RedHat 9 Description: Non-super-user must be able to copy from a file Details:=20 =20 On the attempt to bulk load a table from a file that is owned by the non-superuser current database user, the following error message is printed: =20 "must be superuser to COPY to or from a file" =20 What is the reason for this limitation? This is described in the documentation for the copy command. =20 It can't justifiably be for security reasons because if a web application such as tomcat requires to bulk load tables automatically on a regular b= asis then one would be forced to let the web application connect as superuser, which is very bad for security. No, because you can have the app read the file and then pass the data to the copy command. To do this you use STDIN as the file name. =20 In MySQL bulk loading works for all users. You can use the \copy command in psql to load data from files. =20 We need a Postgresql solution. =20 We have a web application where both MySQL and Postresql are supported. = With Postgresql, the application would have to connect as user postgres. We h= ave to explain this security risk to our clients very clearly. =20 ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
#4
| |||
| |||
|
|
Bernard wrote: This difference of performance is the main reason for the COPY command, and this is also the reason why bulk loading through the JDBC interface will never match the performance of the COPY fith files command. In some admittedly unscientific tests I see less than 10% difference between server-side COPY and client-side COPY FROM STDIN (psql's \copy command) on a 28mb input file. That's down in the per-run noise. Doing it via JDBC will undoubtably add some extra overhead, but I'd estimate that it's about the same sort of overhead as writing your data out to a file from Java in the first place takes. If you've already got the data in a file, why not just use psql's \copy command? This uses COPY FROM STDIN, reads the file as the user running psql, and does not require superuser permissions. The whole architectural setup for such "bulk" loading is a mess. Do you have a concrete suggestion for improving bulk loading that doesn't open security holes? -O ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your message can get through to the mailing list cleanly |
#5
| |||||
| |||||
|
|
Oliver and interested list members: In the majority of bulk load cases, the input exists as a file already |
|
The use of psql in our case requires the launching of an external process from within the running Java application, which is an overhead in processing and code maintenance that must not be under-estimated. |
|
My suggestions for improving the COPY command so it can be used by non-superuser users would be as follows: 1) Add optional Postgresql user permission to use the COPY command with files. |
|
or 2) Split up security risk calculations between the two directions "TO" and "FROM" and relax security. Look at MySQL for clues. The application developer can manage security on file system permission level. |
|
or 3) Close the ident loop in such a way that if a Postgresql user was granted access via ident as an operating system user then the COPY command is executed as a process with that user ID and not as postgres superuser. |
#6
| ||||||
| ||||||
|
|
In the majority of bulk load cases, the input exists as a file already But not necessarily on the server. |
|
The use of psql in our case requires the launching of an external process from within the running Java application, which is an overhead in processing and code maintenance that must not be under-estimated. Certainly supporting COPY via STDIN within the java code seems preferable. |
|
My suggestions for improving the COPY command so it can be used by non-superuser users would be as follows: 1) Add optional Postgresql user permission to use the COPY command with files. Not acceptable, since the ability to copy from a file permits you to read from the internals of the database itself bypassing security restrictions; in particular, if there is a password for the postgres superuser, then it would be trivially exposed by this method. A user with permission to use COPY thus becomes security-equivalent to a superuser in any case. |
|
or 2) Split up security risk calculations between the two directions "TO" and "FROM" and relax security. Look at MySQL for clues. The application developer can manage security on file system permission level. Same problem as above. COPY FROM is not in any sense less of a security risk than COPY TO. |
|
or 3) Close the ident loop in such a way that if a Postgresql user was granted access via ident as an operating system user then the COPY command is executed as a process with that user ID and not as postgres superuser. Postgres does not itself run as root, therefore it lacks the ability to spawn a program that runs under a different userid to itself. |
|
Over the local socket, which is the only context in which ident auth is at all trustable, it would in theory be possible to implement COPY to a file descriptor opened by the client and passed through the socket. I personally think it is unlikely that this would be worth the (not inconsiderable) amount of work needed to implement it, since the performan= ce overhead of copying the data via the socket instead is not a large factor in the overall cost of a large copy. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Bottom line: If this is really important to you, either fix the problem, or provide someone else with incentive to fix the problem. In this case, attempting to appeal to/tear down the ego of the developers is not working, so you will have to resort to more concrete methods, i.e. money. Nice effort though. No matter how much our pride is involved in this, nothing greases the wheels like cash. Sean |
![]() |
| Thread Tools | |
| Display Modes | |
| |