Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use environment variables in modparam() function #2276

Closed
mbrodala opened this issue Apr 7, 2020 · 4 comments
Closed

Cannot use environment variables in modparam() function #2276

mbrodala opened this issue Apr 7, 2020 · 4 comments

Comments

@mbrodala
Copy link

mbrodala commented Apr 7, 2020

Description

I tried to use the $env(NAME) pseudovariable as argument for modparam() calls but evidently the result was empty.

Troubleshooting

Reproduction

Set up auth_ephemeral and add this to your configuration:

modparam("auth_ephemeral", "secret", "$env(AUTH_EPHEMERAL_SECRET)")

Now export AUTH_EPHEMERAL_SECRET=something and start Kamailio with sufficient debug output. You'll see that Kamailio literally uses $env(AUTH_EPHEMERAL_SECRET) as secret instead of inserting the value of the environment variable.

Log Messages

kamailio_1  | 17(23) DEBUG: auth_ephemeral [authorize.c:136]: do_auth(): secret: $env(AUTH_EPHEMERAL_SECRET) (27)

Should be:

kamailio_1  | 17(23) DEBUG: auth_ephemeral [authorize.c:136]: do_auth(): secret: something (9)

Possible Solutions

Replacement of environment variables should be supported in modparams(). (And possibly in all functions.)

Additional Information

  • Kamailio Version - output of kamailio -v
version: kamailio 5.2.1 (x86_64/linux) 
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown 
compiled with gcc 5.3.1

  • Operating System:
$ uname -a
Linux e2193249aa45 4.4.0-128-generic #154-Ubuntu SMP Fri May 25 14:15:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

(Using the Docker image kamailio/kamailio:5.2.1-xenial ATM.)

@miconda
Copy link
Member

miconda commented Apr 8, 2020

This should be possible via:

#substdef "/MYENVSECRET/$env(AUTH_EPHEMERAL_SECRET)/"
modparam("auth_ephemeral", "secret", "MYENVSECRET")

There is another alternative to use command line parameters to set defined values or substdef rules, see kamailio -h.

Note that you may have to use kamailio 5.3.x for some of the above.

I am going to close this one, having alternatives for it. If one wants to implement direct evaluation in modparams, then just do a pull request.

@miconda miconda closed this as completed Apr 8, 2020
@mbrodala
Copy link
Author

I finally got around to test this but it seems I'm doing something wrong:

#!substdef "/DBRWUSER/$env(DBRWUSER)/g"
#!substdef "/DBRWPW/$env(DBRWPW)/g"
#!substdef "/DBHOST/$env(DBHOST)/g"
#!substdef "/DBNAME/$env(DBNAME)/g"

#!define DBURL "mysql://DBRWUSER:DBRWPW@DBHOST/DBNAME"

Now trying to start Kamailio (5.3.3 as suggested) fails:

kamailio_1  |  0(1) ERROR: <core> [core/pvapi.c:923]: pv_parse_spec2(): error searching pvar "env"
kamailio_1  |  0(1) ERROR: <core> [core/pvapi.c:1126]: pv_parse_spec2(): wrong char [D/68] in [$env(DBRWUSER)/g] at [5 (5)]
kamailio_1  |  0(1) ERROR: <core> [core/re.c:170]: parse_repl(): bad specifier in replace part /$env(DBRWUSER)/g
kamailio_1  |  0(1) ERROR: <core> [core/ppcfg.c:69]: pp_subst_add(): bad subst expression: /DBRWUSER/$env(DBRWUSER)/g
kamailio_1  |  0(1) ERROR: <core> [core/ppcfg.c:96]: pp_substdef_add(): subst rule cannot be added

I also tried the following but it doesn't make a difference:

#!substdef "!DBURL!mysql://$env(DBRWUSER):$env(DBRWPW)@$env(DBHOST)/$env(DBNAME)!"

@miconda
Copy link
Member

miconda commented Apr 27, 2020

Try to load pv module before subsdef definitions. I haven't added this feature to know its constraints, but I see that the error is not finding $env()

@mbrodala
Copy link
Author

This looks way better, the error is gone now. Thanks. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants