Encryption key file path issue

Posts: 53
Joined: 10/03/2008

Following the instructions here: http://www.ubercart.org/docs/user/2731/credit_card_settings

I have a private key folder created outside of the Web root. It has full permissions for the moment in order to set up the configuration. But when I try saving my payment settings config in Ubercart, I get the following error:

* warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(../private) is not within the allowed path(s): (/var/www/vhosts/sitename.com/httpdocs:/tmp) in /var/www/vhosts/sitename.com/httpdocs/sites/all/modules/ubercart/payment/uc_credit/uc_credit.module on line 771.
* You have specified a non-existent directory.

The directory is there and it has full permissions. Any ideas why this error is occurring?

Also for testing purposes do folks recommend using debug mode?

-backdrifting

Posts: 1377
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

That error is a php.ini issue. It basically means that your server is setup to not allow any scripts access to files outside of the directories specified in the open_basedir directive.

Easiest way around this, if you have access, is to go into your domain's "conf" folder, and edit the httpd.include file - this contains the "Local" values for open_basedir. You can either delete the webroot folder, or add another folder to the list. Something like:

/path/to/site/httpdocs:/tmp:/path/to/site

This allows scripts access to the httpdocs folder, the tmp folder, and the first folder above the webroot (the webroot's parent folder).

If you don't have access to php.ini (you might want to change the basedir settings there as well) you should email your host's support team and ask if they can.

About debug mode, yes, sometimes debug mode is helpful in testing CC numbers. But it depends on what you are trying to debug, if it's not CC numbers then other things are more suitable.

EDIT: To clarify, the "conf" folder I mentioned would be in:
/path/to/domain/conf

(parallel to)
/path/to/domain/httpdocs

Hope this helps.

http://ez.no/ezpublish/documentation/configuration/troubleshooting/open_...

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 53
Joined: 10/03/2008

Thanks for your assistance. Well unfortunately I don't have access to the "conf" folder so I've asked my host to make the tweaks. Hopefully they can do this.

Other question - is it absolutely necessary/imperative to keep the encryption key in a folder outside of the main Web folder (www or httpdocs)? Could I keep the key in the Web folder but just keep the permissions locked down? Just curious on this.

Thanks for your note on debug mode as well.

-backdrifting

Posts: 1377
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Yeah your hosting provider should be able to do that, no problem.

I think it is necessary to keep the encryption key outside of the webroot. Even with permissions set on a per-file basis, it's still possible for someone with enough knowledge to get access to files if they know they are there. (And they can find ways to learn about which files exist within the public root).

It's really just another added level of security - a file is less likely to get snooped or stumbled upon if it can't be accessed at all by the public user. I don't think it's absolutely a requirement, but more of a strategy for keeping your sensitive info secure.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 53
Joined: 10/03/2008

Thanks for your assistance with this. My host successfully set up the access to the folder and I have the encryption file in there now. It's all working.

Now one further question - I gave that folder all permissions so the file could be written to that location. According to the Ubercart docs on this it states:

"You will need to grant permissions on the folder that allow Drupal to write to it, but you can change this once the encryption file has been created."

So should I turn off all the read/write/exe access to that folder now that the file has been written? Just leave the read/write access for "owner"?

Thanks,

-backdrifting

Posts: 1377
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

You can get rid of all write access - just making it read only is fine - for all users, or just Owner. But test that once you make the change to be sure your checkout still works (it should).

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 53
Joined: 10/03/2008

Actually, I removed the write access and then I enabled COD (in addition to the credit card payment settings I already configured). When I then went to re-save my configuration I get the following errors:

* warning: fopen(../private/encrypt.test) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/sitename.com/httpdocs/sites/all/modules/ubercart/payment/uc_credit/uc_credit.module on line 776.
* Cannot write to directory, please verify the directory permissions.

So I went into the server and turned write permissions back on for the ../private folder. Then I saved the config again, and now I'm still getting the error.

So it was working, and now it's not working. What should I do?

Any suggestions?

-backdrifting

Posts: 53
Joined: 10/03/2008

Ok, I just added execute permissions to all the groups and now it's working. However we don't want to add execute permissions correct? So how can I remove the execute permissions but still get this to work?

-backdrifting

Posts: 53
Joined: 10/03/2008

... or is it that Drupal just needs to create that encryption file and then I can take those permissions off, but not re-save the configuration in Ubercart? Is the issue because I had removed the permissions and then tried saving a new config with COD?

-backdrifting

Posts: 1377
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Execute permissions it is, then. I wasn't sure how Ubercart was getting the data, but I think perhaps if it's including it in the script, maybe it does need those perms as well (and not just Read). As long as you only give those Exec perms to the Owner you should be fine. (I think it'll be 644).

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 2357
Joined: 08/07/2007
AdministratoreLiTe!

Permissions are weird on directories. Read lets you know what files are in it, but that's all. Write lets you create files in that directory. However, Execute lets you get additional information about the files, like filesize and timestamp.

The private directory should probably have permissions of 700 (rwx for owner) or 500 (r-x for owner), while the encryption key file should have just read (400). Just make sure that the owner is the Apache process, so that PHP can use it.

Posts: 53
Joined: 10/03/2008

Excellent. Thanks to both of you for explanations and suggestions. I'll review the permissions and make sure I've got it set correctly per your suggestions/instructions.

Thanks again.

-backdrifting

Posts: 4
Joined: 11/30/2008

Hi to all on the Ubercart forums (sorry, my first post) - firstly, many thanks for a FANTASTIC e-commerce package Smiling

I wonder if anyone can help - I'm having similar problems with a site that I've just moved to a live server (still under basic auth). The error I'm getting is;

warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(../keys/uc_credit.key) is not within the allowed path(s): (/var/www/vhosts/sitename.com/httpdocs:/tmp) in /var/www/vhosts/sitename.com/httpdocs/sites/all/modules/ubercart/payment/uc_credit/uc_credit.module on line 1762.

The strange thing is, my keys folder is /var/www/vhosts/sitename.com/keys and I've created a /conf/vhosts.conf to override /conf/httpd.include (I'm using Plesk on a CentOS box) and I've tried both

<Directory /var/www/vhosts/sitename.com/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/sitename.com/httpdocs:/tmp:/var/www/vhosts/sitename.com/keys"
</Directory>
AND
<Directory /var/www/vhosts/sitename.com/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/sitename.com/httpdocs:/tmp:/var/www/vhosts/sitename.com"
</Directory>

Have I been a complete wally and missed something here??? I also have another test install of Ubercart running on the same server using an almost identical setup but that site has no issues.

The only thing I can think of, being relatively new to Drupal and Ubercart, is that something may have gone a bit screwy when I moved the site from a local XAMPP install in this case. Would going from one level down in XAMPP (e.g. htdocs/sitename/DRUPAL+UBERCART FILES) to a top level install on this server make any difference anywhere?

Many thanks in advance Smiling

Posts: 4
Joined: 11/30/2008

OK, sorry about this - after giving up and going to bed at 04:00 I managed to look at this again today with a semi-fresh pair of eyes...

Turns out that all I needed to do was remove the basic auth and ta-da it worked (all except the permissions)!! Trouble is, I'd still really like to have basic auth. Guess it's time to see if I can now work out how to get /var/www/vhosts/sitename.com/keys to avoid such authentication.

So again, sorry to have wasted your time with my first post.

Posts: 5
Joined: 08/11/2008

I am in the same boat as you were here, and I am not sure how you fixed it. What do you mean by "basic auth" and what would I need to get around it?

Posts: 1377
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Are you having an open_basedir issue? What is the problem exactly?

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 5
Joined: 08/11/2008

Here is my error:

warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(../keys/uc_credit.key) is not within the allowed path(s): (/var/www/vhosts/mysite.com/httpdocs:/tmp) in /var/www/vhosts/mysite.com/httpdocs/sites/all/modules/ubercart/payment/uc_credit/uc_credit.module on line 1359.

I am a bit unfamiliar with all this, but I did create the same file as axel_pressbutton:

My keys folder is /var/www/vhosts/sitename.com/keys and I've created a /conf/vhosts.conf to override /conf/httpd.include

Its there, but what else do I need to do?

<Directory /var/www/vhosts/sitename.com/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/sitename.com/httpdocs:/tmp:/var/www/vhosts/sitename.com/keys"
</Directory>

Thanks in advance for your help.

Posts: 1377
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

It looks like you just need to set the encryption path as absolute?

Right now it might be "../keys/uc_credit.key" but if you change it to /var/www/vhosts/mysite.com/keys it should work at that point.

The thing about httpd.include too, is that those files get overwritten when you restart the httpd service. So once you've made the change, you need to restart apache (use apachectl restart) and then the changes will take effect. You can verify this by going into the php status info in the admin. (/admin/logs/status/php)

You might also check to see if there is a Master Value for open_basedir. If there is, then it might be overriding your local values set in httpd.include. If that's the case, you need to open php.ini and comment out the open_basedir directive. (php.ini is usually at /etc/php.ini)

HTH.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 4
Joined: 11/30/2008

Hi Bevinlorenzo - sorry, I've not been around for a few days.

"basic auth" is short for "Basic Authentication" and I'm guessing you're not using it if you're not sure what it is. I use it to restrict access to the site until I want people to see it. All it does is lock the site down and requests a username and password when you visit the site. See http://en.wikipedia.org/wiki/Basic_access_authentication

In my case all I had to do was to disable this. Again, I'm not sure if this is just a CentOS/Plesk issue.

I can't recall, but I'm sure I tried the fully qualified path without success - I'll Try some of TorgosPizza's last comments to see if i can get my setup to work happily with basic auth in place.