I read this http://www.apacheweek.com/features/userauth and I try to accomplish the same in Openshift but i don't know how.
Im using rhc and I tried to connect across ssh to my app, but I don't have permissions to use sudo su
so I can't continue.
For example when I try to create the file nano /usr/local/etc/httpd
I can't because I don't have root privileges.
> ls -la /usr/local/etc
total 20
drwxr-xr-x. 2 root root 4096 jun 5 20:58 .
drwxr-xr-x. 14 root root 4096 dic 11 2013 ..
-rw-r--r--. 1 root root 1807 may 19 15:23 oom-kill-disable.conf
-rw-------. 1 root root 1675 may 21 14:51 ops_file_transfer_upload_id_rsa
-rw-r-----. 1 root root 399 jun 5 20:58 partitioner_disk_definitions.yaml
If I have a wrong approach i would appreciate you can guide me.
UPDATE
As @davelopercorey suggest now I'm using .htaccess file
AuthType Basic
AuthName "Authentication"
AuthUserFile ${OPENSHIFT_REPO_DIR}.htpasswd
Require valid-user
And adding user and his password
htpasswd -cb .htpasswd myuser mypass
Authenticating prompt is showing but my user and pass are not validating well.
I have use whereis htpasswd
to ensure im writing the correct path and issues still persists.
If you are using one of the cartridges that supports .htaccess files (such as python or php), you can put your .htpasswd file anywhere in the file system. I suggest placing it in your ~/app-root/data directory, then you can point to it from your .htaccess file at that location and use the authentication that you want based on the rules that you put in your .htaccess file for different file types or directories, etc.
The final solution. Thanks to @developercorey
In openshift there is a enviroment variable called $OPENSHIFT_REPO_DIR, is the path of your working directory i.e. /var/lib/openshift/myuserlongid/app-root/runtime/repo/
I create a new enviroment variable called SECURE wrapping the folder path.
rhc set-env SECURE=/var/lib/openshift/myuserlongid/app-root/data --app myappname
Finally I connect to my app with ssh
rhc ssh myappname
And create the .htpasswd file
htpasswd -c $SECURE/.htpasswd <username>
Note: The -c option to htpasswd creates a new file, overwriting any existing htpasswd file. If your intention is to add a new user to an existing htpasswd file, simply drop the -c option.
.htaccess file
AuthType Basic
AuthName "Authentication"
AuthUserFile ${SECURE}/.htpasswd
Require valid-user
First connect to the server using ssh:
rhc ssh yourappname
then go to app directory:
cd ${OPENSHIFT_REPO_DIR}
run the following command , and then copy the result:
${OPENSHIFT_REPO_DIR}
and create in this directory file .htaccess:
nano .htaccess
but replace "/var/lib/openshift/xxxxxxxxxxxxxxxxxxxxxxxx/app-root/runtime/repo/" on the previously copied, it should be in the file .htaccess:
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/var/lib/openshift/xxxxxxxxxxxxxxxxxxxxxxxx/app-root/runtime/repo/.htpasswd"
Require valid-user
then create .htpasswd file:
htpasswd -c .htpasswd yourusername
Then you save it.
We can use internal OPENSHIFT_DATA_DIR variable, so for ~/app-root/data/.htpasswd
in my case is enough:
AuthType Basic
AuthName "Authentication"
AuthUserFile ${OPENSHIFT_DATA_DIR}/.htpasswd
Require valid-user