# irule help

**URL:** <https://community.f5.com/t/irule-help/13048>\
**Category:** Technical Forums\
**Tags:** big-ip, ltm, application-delivery\
**Created:** [October 11, 2018, 9:58am UTC](https://community.f5.com/t/irule-help/13048 "2018-10-11T09:58:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikegray\_198028](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mikegray\_198028](https://community.f5.com/u/mikegray_198028)\
**Post date:** [October 11, 2018, 9:58am UTC](https://community.f5.com/t/irule-help/13048/1 "2018-10-11T09:58:48Z")

</div>

Team,

i have one requirement for url based client authentication. like enable client auth only for /app and /app1. no client auth required for any other path

---

<div class="post-metadata">

**Author:** ![ka1021](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@ka1021](https://community.f5.com/u/ka1021)\
**Post date:** [October 11, 2018, 10:24am UTC](https://community.f5.com/t/irule-help/13048/2 "2018-10-11T10:24:26Z")

</div>

Hi Mike,

What kind of authentication you want to perform?

Kaustubh

---

<div class="post-metadata">

**Author:** ![mikegray\_198028](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mikegray\_198028](https://community.f5.com/u/mikegray_198028)\
**Post date:** [October 11, 2018, 12:23pm UTC](https://community.f5.com/t/irule-help/13048/3 "2018-10-11T12:23:57Z")

</div>

client certificate based authentication

---

<div class="post-metadata">

**Author:** ![PeteWhite](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/petewhite/32/33768_2.png) [@PeteWhite](https://community.f5.com/u/PeteWhite)\
**Post date:** [October 11, 2018, 12:45pm UTC](https://community.f5.com/t/irule-help/13048/4 "2018-10-11T12:45:48Z")

</div>

How can that work? You have to have setup an SSL session before being able to send the HTTP request which includes the URI. You either do client auth for all requests or for none.

---

<div class="post-metadata">

**Author:** ![mikegray\_198028](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mikegray\_198028](https://community.f5.com/u/mikegray_198028)\
**Post date:** [October 11, 2018, 3:19pm UTC](https://community.f5.com/t/irule-help/13048/5 "2018-10-11T15:19:56Z")

</div>

iam looking something like this [https://devcentral.f5.com/s/articles/selective-client-cert-authentication](https://devcentral.f5.com/s/articles/selective-client-cert-authentication)

¬†

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [October 11, 2018, 3:41pm UTC](https://community.f5.com/t/irule-help/13048/6 "2018-10-11T15:41:05Z")

</div>

You could try something like this: [https://devcentral.f5.com/questions/switch-off-client-auth-or-switch-ssl-profile-altogether-sslcert-mode-or-sslprofile-](https://devcentral.f5.com/questions/switch-off-client-auth-or-switch-ssl-profile-altogether-sslcert-mode-or-sslprofile-)

It’s also worth noting that this can be very easily achieved, without iRules, using Access Policy Manager (APM).

---

<div class="post-metadata">

**Author:** ![action\_322447](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@action\_322447](https://community.f5.com/u/action_322447)\
**Post date:** [October 12, 2018, 5:21pm UTC](https://community.f5.com/t/irule-help/13048/7 "2018-10-12T17:21:07Z")

</div>

Edit: Just realized you said you don’t have APM. Woops.

I have a similar use case. I have one VIP that I hang multiple websites off of. When someone goes to a certain URI, it starts and APM session and they log in with their certificate through APM, flow through VPE etc.

My default switch has ACCESS::disable which allows everyone initially. If someone goes to a specific URI, it sets a custom variable, if that variable exists, access is enabled for the remainder of their session.

One thing that I did have to configure the APM VPE at the client cert prompt: if it failed and the http host value was that public site, I had it redirect to the public site homepage so the user didn’t get some f5 APM error. I am not sure how to do that in an iRule.

my iRule looks something like this:

```tcl
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
    "www.site1.com" {
        pool pool1
        switch -glob [string tolower [HTTP::uri]] {
            "*app" {
                log local0. "inside app uri switch"
                ACCESS::enable
                set uri 1
                ACCESS::session data set session.ssl.custom.cac.uri $uri
            } "*app1*" {
                log local0. "inside app1 uri switch"
                ACCESS::enable
                set uri 1
                ACCESS::session data set session.ssl.custom.cac.uri $uri
            } default {
                log local0. "inside default switch"
                if { [info exists [ACCESS::session data get session.ssl.custom.cac.uri]] } {
                ACCESS::enable
                log local0. "default access exists [ACCESS::session data get session.ssl.custom.cac.uri]"
                } else {
                    ACCESS::disable
                }
            }
        }
    }
    "www.site2.com" {
        pool pool2
        SSL::disable serverside
        ACCESS::disable
    }
}

```

Not sure if there’s anything wrong about doing it this way, or if there’s a better way, but it is working for me. Feedback appreciated.
