Kerberos support broken on MSVC builds for Windows x64?
I was experimenting with building with MIT Kerberos support on 64 bit
Windows using MSVC and ran into a number of linker errors along the lines
of:
"C:\Users\dpage\Downloads\postgresql-12.4\pgsql.sln" (default target) (1) ->
"C:\Users\dpage\Downloads\postgresql-12.4\zic.vcxproj" (default target) (2)
->
(Link target) ->
LINK : fatal error LNK1181: cannot open input file
'C:\Progra~1\MIT\Kerberos\lib.obj'
[C:\Users\dpage\Downloads\postgresql-12.4\zic.vcxproj]
That was after I had to manually add the include and lib paths in
buildenv.pl. Diving in a bit further I found a couple of things:
1) The only buildfarm machine doing 64bit Windows Kerberos enabled builds
with MSVC is hammerkop. It enables it by setting the "krb5" option in
config.pl, however, as far as I can see (going back to 9.5), the option is
actually "gss". I can't see any sign in the log for the make step that it
actually is making any attempt to build with Kerberos, despite the UI
showing the icon for it.
2) I can't find anything in the MSVC build scripts in src/tools/msvc to
deal with 64bit Kerberos builds - Solution.pm seems to unconditionally try
to link with the 32bit libraries (e.g. lib/i386/krb5_32.lib instead of
lib/amd64/krb5_64.lib).
I'm assuming noone has tried a build with 64bit Kerberos, or am I missing
something?
Sidenote: I'm not sure even a 32bit Kerberos build will work, as
Solution.pm assumes the headers are in $self->{options}->{gss} .
'\inc\krb5', however in at least the latest installer from MIT they're
actually in $self->{options}->{gss} . '\include'.
--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake
On Tue, Sep 1, 2020 at 4:22 PM Dave Page <dpage@pgadmin.org> wrote:
I was experimenting with building with MIT Kerberos support on 64 bit
Windows using MSVC and ran into a number of linker errors along the lines
of:"C:\Users\dpage\Downloads\postgresql-12.4\pgsql.sln" (default target) (1)
->
"C:\Users\dpage\Downloads\postgresql-12.4\zic.vcxproj" (default target)
(2) ->
(Link target) ->
LINK : fatal error LNK1181: cannot open input file
'C:\Progra~1\MIT\Kerberos\lib.obj'
[C:\Users\dpage\Downloads\postgresql-12.4\zic.vcxproj]That was after I had to manually add the include and lib paths in
buildenv.pl. Diving in a bit further I found a couple of things:1) The only buildfarm machine doing 64bit Windows Kerberos enabled builds
with MSVC is hammerkop. It enables it by setting the "krb5" option in
config.pl, however, as far as I can see (going back to 9.5), the option
is actually "gss". I can't see any sign in the log for the make step that
it actually is making any attempt to build with Kerberos, despite the UI
showing the icon for it.2) I can't find anything in the MSVC build scripts in src/tools/msvc to
deal with 64bit Kerberos builds - Solution.pm seems to unconditionally try
to link with the 32bit libraries (e.g. lib/i386/krb5_32.lib instead of
lib/amd64/krb5_64.lib).I'm assuming noone has tried a build with 64bit Kerberos, or am I missing
something?Sidenote: I'm not sure even a 32bit Kerberos build will work, as
Solution.pm assumes the headers are in $self->{options}->{gss} .
'\inc\krb5', however in at least the latest installer from MIT they're
actually in $self->{options}->{gss} . '\include'.
Attached is a patch against 12.4 for the build system in case anyone wants
to play (I'll do it properly against the head branch later). I'm guessing
this will work for < 12, as with 12 I'm now getting the following which
looks like it's related to GSS encryption:
"C:\Users\dpage\Downloads\postgresql-12.4\pgsql.sln" (default target) (1) ->
"C:\Users\dpage\Downloads\postgresql-12.4\pgcrypto.vcxproj" (default
target) (2) ->
"C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj" (default
target) (3) ->
(Link target) ->
be-secure-gssapi.obj : error LNK2019: unresolved external symbol setenv
referenced in function secure_open_gssapi
[C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]
.\Release\postgres\postgres.exe : fatal error LNK1120: 1 unresolved
externals [C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]
I'll dig into that some more.
--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake
Attachments:
msvc64-kerberos.diffapplication/octet-stream; name=msvc64-kerberos.diffDownload
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 9d2345689a..b974b149ee 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -729,10 +729,19 @@ sub AddProject
}
if ($self->{options}->{gss})
{
- $proj->AddIncludeDir($self->{options}->{gss} . '\inc\krb5');
- $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\krb5_32.lib');
- $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\comerr32.lib');
- $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\gssapi32.lib');
+ $proj->AddIncludeDir($self->{options}->{gss} . '\include');
+ if ($self->{platform} eq 'Win32')
+ {
+ $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\krb5_32.lib');
+ $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\comerr32.lib');
+ $proj->AddLibrary($self->{options}->{gss} . '\lib\i386\gssapi32.lib');
+ }
+ else
+ {
+ $proj->AddLibrary($self->{options}->{gss} . '\lib\amd64\krb5_64.lib');
+ $proj->AddLibrary($self->{options}->{gss} . '\lib\amd64\comerr64.lib');
+ $proj->AddLibrary($self->{options}->{gss} . '\lib\amd64\gssapi64.lib');
+ }
}
if ($self->{options}->{iconv})
{
Greetings,
* Dave Page (dpage@pgadmin.org) wrote:
Attached is a patch against 12.4 for the build system in case anyone wants
to play (I'll do it properly against the head branch later). I'm guessing
this will work for < 12, as with 12 I'm now getting the following which
looks like it's related to GSS encryption:"C:\Users\dpage\Downloads\postgresql-12.4\pgsql.sln" (default target) (1) ->
"C:\Users\dpage\Downloads\postgresql-12.4\pgcrypto.vcxproj" (default
target) (2) ->
"C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj" (default
target) (3) ->
(Link target) ->
be-secure-gssapi.obj : error LNK2019: unresolved external symbol setenv
referenced in function secure_open_gssapi
[C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]
.\Release\postgres\postgres.exe : fatal error LNK1120: 1 unresolved
externals [C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]I'll dig into that some more.
Yes, that'd be in the GSSENC code, which I hadn't been expecting to be
used under Windows. If you're successful, I don't have any issue
helping to make that work, though I'm curious if you're trying to build
with MIT KfW (which is rather ancient these days, being based on krb5
1.13 and not updated since..) or with a more current release...?
Of course, it'd be good to get a buildfarm animal in place that's
actually testing this if we're going to make it work.
Regarding the setenv() call, should be able to use pgwin32_putenv() in
place on Windows, I'd think..?
Thanks,
Stephen
Hi
On Tue, Sep 1, 2020 at 5:29 PM Stephen Frost <sfrost@snowman.net> wrote:
Greetings,
* Dave Page (dpage@pgadmin.org) wrote:
Attached is a patch against 12.4 for the build system in case anyone
wants
to play (I'll do it properly against the head branch later). I'm guessing
this will work for < 12, as with 12 I'm now getting the following which
looks like it's related to GSS encryption:"C:\Users\dpage\Downloads\postgresql-12.4\pgsql.sln" (default target)
(1) ->
"C:\Users\dpage\Downloads\postgresql-12.4\pgcrypto.vcxproj" (default
target) (2) ->
"C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj" (default
target) (3) ->
(Link target) ->
be-secure-gssapi.obj : error LNK2019: unresolved external symbol setenv
referenced in function secure_open_gssapi
[C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]
.\Release\postgres\postgres.exe : fatal error LNK1120: 1 unresolved
externals [C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]I'll dig into that some more.
Yes, that'd be in the GSSENC code, which I hadn't been expecting to be
used under Windows. If you're successful, I don't have any issue
helping to make that work, though I'm curious if you're trying to build
with MIT KfW (which is rather ancient these days, being based on krb5
1.13 and not updated since..) or with a more current release...?
I'm currently using the KFW 4.1 build from MIT. I've tried building it
myself but it requires a very old toolchain (which defeated the point of
what I was trying to do at the time).
I haven't yet looked to see if the source for krb5-1.8.2 will build or even
has the right bits in it for Windows - as I'm sure you know MIT seem to
maintain an entirely different version for Windows for which I assume
there's a reason.
Of course, it'd be good to get a buildfarm animal in place that's
actually testing this if we're going to make it work.
Fixing the config on hamerkop should deal with that I think. Though I am
confused as to why the Buildfarm UI thinks it has Kerberos support enabled
- did we change the config parameter from krb5 to gss some time prior to
9.5? If so, that could explain it.
Regarding the setenv() call, should be able to use pgwin32_putenv() in
place on Windows, I'd think..?
Right, I imagine so. It's on my todo...
--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake
Greetings,
* Dave Page (dpage@pgadmin.org) wrote:
On Tue, Sep 1, 2020 at 5:29 PM Stephen Frost <sfrost@snowman.net> wrote:
* Dave Page (dpage@pgadmin.org) wrote:
Attached is a patch against 12.4 for the build system in case anyone
wants
to play (I'll do it properly against the head branch later). I'm guessing
this will work for < 12, as with 12 I'm now getting the following which
looks like it's related to GSS encryption:"C:\Users\dpage\Downloads\postgresql-12.4\pgsql.sln" (default target)
(1) ->
"C:\Users\dpage\Downloads\postgresql-12.4\pgcrypto.vcxproj" (default
target) (2) ->
"C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj" (default
target) (3) ->
(Link target) ->
be-secure-gssapi.obj : error LNK2019: unresolved external symbol setenv
referenced in function secure_open_gssapi
[C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]
.\Release\postgres\postgres.exe : fatal error LNK1120: 1 unresolved
externals [C:\Users\dpage\Downloads\postgresql-12.4\postgres.vcxproj]I'll dig into that some more.
Yes, that'd be in the GSSENC code, which I hadn't been expecting to be
used under Windows. If you're successful, I don't have any issue
helping to make that work, though I'm curious if you're trying to build
with MIT KfW (which is rather ancient these days, being based on krb5
1.13 and not updated since..) or with a more current release...?I'm currently using the KFW 4.1 build from MIT. I've tried building it
myself but it requires a very old toolchain (which defeated the point of
what I was trying to do at the time).
I haven't yet looked to see if the source for krb5-1.8.2 will build or even
has the right bits in it for Windows - as I'm sure you know MIT seem to
maintain an entirely different version for Windows for which I assume
there's a reason.
I'm a bit confused as to why you'd consider trying 1.8.2- did you mean
1.18.2 there, perhaps..? That's what I would think to try, since, as I
understand it from following the Kerberos Dev list (which is pretty
responsive...) has been updated to work with newer Windows build
toolchains.
Of course, it'd be good to get a buildfarm animal in place that's
actually testing this if we're going to make it work.Fixing the config on hamerkop should deal with that I think. Though I am
confused as to why the Buildfarm UI thinks it has Kerberos support enabled
- did we change the config parameter from krb5 to gss some time prior to
9.5? If so, that could explain it.
Looks to be run by SRA OSS.. Perhaps reaching out to them to ask about
it would help?
Regarding the setenv() call, should be able to use pgwin32_putenv() in
place on Windows, I'd think..?Right, I imagine so. It's on my todo...
Alright.
Thanks,
Stephen
Hi
On Wed, Sep 2, 2020 at 9:05 AM Dave Page <dpage@pgadmin.org> wrote:
Yes, that'd be in the GSSENC code, which I hadn't been expecting to be
used under Windows.
Here's a patch to make it build successfully (against head). I believe the
changes to Solution.pm should be back patched all the way, and the rest to
12.
Testing however, has been more problematic - I suspect at least partly
because of my Kerberos newbie-ness. I have a test server in an Ubuntu VM,
which I've used quite successfully to authenticate against another VM
running PG 12 on Ubuntu, from both Ubuntu and Windows clients. Using that,
but with a Windows client running MIT Kerberos I find that getting a ticket
takes a good 30 seconds or so. Postgres also seems to get it's ticket
successfully via the keytab file:
C:\pg>"c:\Program Files\MIT\Kerberos\bin\klist.exe"
Ticket cache: API:Initial default ccache
Default principal: dpage@PGADMIN.ORG
Valid starting Expires Service principal
09/02/20 15:06:49 09/03/20 01:06:49 krbtgt/PGADMIN.ORG@PGADMIN.ORG
renew until 09/03/20 15:06:31
09/02/20 15:07:06 09/03/20 01:06:49 postgres/win-ilt1arj8a9c@
renew until 09/03/20 15:06:31
09/02/20 15:07:06 09/03/20 01:06:49 postgres/win-ilt1arj8a9c@PGADMIN.ORG
renew until 09/03/20 15:06:31
However, If I try to login using host + gss in the pg_hba.conf file, I then
get:
C:\pg>bin\psql postgres
psql: error: could not connect to server: SSPI continuation error: No
credentials are available in the security package
(8009030e)
If I try to use hostgssenc + gss, it looks like it's not even trying to
encrypt:
C:\pg>bin\psql postgres
psql: error: could not connect to server: FATAL: no pg_hba.conf entry for
host "::1", user "dpage", database "postgres", SSL off
Any ideas?
--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake
Attachments:
msvc64-kerberos-v2.diffapplication/octet-stream; name=msvc64-kerberos-v2.diffDownload
��d i f f - - g i t a / s r c / b a c k e n d / l i b p q / b e - s e c u r e - g s s a p i . c b / s r c / b a c k e n d / l i b p q / b e - s e c u r e - g s s a p i . c
i n d e x 6 4 4 2 7 f 1 8 5 b . . 1 b 3 0 a 2 a 1 2 5 1 0 0 6 4 4
- - - a / s r c / b a c k e n d / l i b p q / b e - s e c u r e - g s s a p i . c
+ + + b / s r c / b a c k e n d / l i b p q / b e - s e c u r e - g s s a p i . c
@ @ - 4 9 0 , 7 + 4 9 0 , 2 1 @ @ s e c u r e _ o p e n _ g s s a p i ( P o r t * p o r t )
* d o e s n '