May 10th, 2013 |
Database, Tech Talk | 2 Comments
Let’s face it, the pg_hba.conf file is a pain in the ass to use regularly. Sure, reloading the database will cause it to re-read this file, but with a lot of active users and frequent changes, this isn’t really tenable.
Luckily lurking deep within its bowels, PostgreSQL has a little-known feature that can easily be overlooked because it’s so humbly stated. Here’s the manual entry for pg_hba.conf for the user section:
Specifies which database user name(s) this record matches. The value all specifies that it matches all users. Otherwise, this is either the name of a specific database user, or a group name preceded by +. (Recall that there is no real distinction between users and groups in PostgreSQL; a + mark really means “match any of the roles that are directly or indirectly members of this role”, while a name without a + mark matches only that specific role.) Multiple user names can be supplied by separating them with commas. A separate file containing user names can be specified by preceding the file name with @.
The implications of this are staggering and should be shouted from the rooftops frequently and with much fanfare. But what part of that paragraph is the feature that has me raving about its awesomeness? The + decorator for a specified role.
Initially, it might occur to a DBA to simply take advantage of this ability to use existing roles and segregate access by implementing a few well-placed group lines into the file. Say we wanted to allow all DB developers to connect, and our local subnet had a range for desktop systems. We could do this:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all +developer 10.10.0.0/16 md5
And viola! Instead of granting access to each individual person, anyone in the developer group could connect provided they had a password. Neat, eh?
Ah, but it goes much deeper than that.
What happens when we apply this to the entire file, and completely purge all individual user entries entirely? Even for automated or batch systems? We get the opportunity to build a connection policy enforceable by in-database methods. Instead of modifying the access file and reloading the database, GRANT and REVOKE become the only commands we’ll ever need.
Imagine we have our production environment and we’ve locked down the entire pg_hba.conf file from external access with this single line for our internal VPN:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all +prod_env 10.0.0.0/8 md5
Now, being quite this permissive is probably not a good idea. In a real setup, the production system should only accessible from a very limited range of addresses. However, for the purposes of this discussion, it’s fine. Next, let’s create the
prod_env group, and a user to grant it to:
CREATE ROLE prod_env WITH NOLOGIN;
CREATE USER foobar WITH PASSWORD 'testing';
GRANT prod_env TO foobar;
foobar user can connect as often as he likes, and we didn’t have to touch anything external to the database after the initial configuration. Here’s where it gets fun. The
foobar user has been naughty, and we’re kicking him out of production. Our prod environment is regularly copied into stage in redacted form, so it’s still OK for him to connect there. Let’s save ourselves some effort and add a
REVOKE prod_env FROM foobar;
CREATE ROLE stage_env WITH NOLOGIN;
GRANT stage_env TO foobar;
And in our stage environment, it would have a pg_hba.conf similar to what we have in production:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all +stage_env 10.0.0.0/8 md5
Now the same user can exist in both environments, but only be able to connect to one. This kind of interleaving is easy to accomplish and the controls can be as fine or coarse as your imagination demands.
But it actually gets better!
Suppose our organization has a support team, who we clearly don’t want to give superuser access, but they want to regularly modify user rights. Well, we could grant them every group
WITH GRANT OPTION for later distribution, but that’s not really ideal. How about a function they can use instead?
CREATE OR REPLACE FUNCTION grant_conn_role(
username VARCHAR, rolename VARCHAR
RETURNS BOOLEAN AS
-- Only allow 'env' roles to be granted this way. That extension is
-- reserved for connection restrictions.
IF rolename !~ E'\_env' THEN
-- Don't allow the use of this function to grant superuser access!
PERFORM (WITH RECURSIVE rolecheck AS (
FROM pg_authid a
JOIN rolecheck c ON (c.rolname = a.rolname)
JOIN pg_auth_members m ON (m.roleid = a.oid)
JOIN pg_authid r on (m.member = r.oid)
WHERE rolname = rolename);
IF FOUND THEN
-- It's now safe to do the grant.
EXECUTE 'GRANT ' || quote_ident(rolename) || ' TO ' ||
RETURN (SELECT pg_has_role(username, rolename, 'MEMBER'));
$BODY$ LANGUAGE plpgsql SECURITY DEFINER;
REVOKE EXECUTE ON FUNCTION grant_conn_role(VARCHAR, VARCHAR) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION grant_conn_role(VARCHAR, VARCHAR) TO support;
Now anyone in the
support group can modify user rights as if they were a superuser. Of course, we plugged the obvious hole so support users can’t grant themselves a superuser capable role. But we also want this to only work with roles that fit a certain naming scheme. In this case, anything ending in
_env is set aside for connection wrangling. You could just as easily use
conn_ as a prefix instead, or any preferable nomenclature. Just modify the function to reflect the standard.
As DBAs, we want to do as little work as possible while simultaneously providing a secure and reliable system. Reloading database configs unnecessarily and doing all user management personally doesn’t really reflect that goal. We might as well use the tools the database provides to be lazy but still protect the environment.
With PostgreSQL, this is both easy and surprisingly powerful, all thanks to
pg_hba.conf making itself redundant.
April 26th, 2013 |
Database, News, Tech Talk | 16 Comments
A little while ago, I wrote to the PostgreSQL general mailing list that I’d been approached by Packt Publishing to contribute a quick manual on doing PostgreSQL backups: Instant PostgreSQL Backup and Restore How-to. They’re the same guys who published Greg Smith’s PostgreSQL 9.0 High Performance book which everyone seems to swear by.
The goal of the backup book was to distill the PostgreSQL documentation, tools, and Wiki down to a collection of short step-by-step guides much like the O’Reilly nutshell series. A lot of the backup recipes we DBAs trade back and forth as a matter of course may not be so obvious, and I threw a couple tricks in for advanced users, to boot.
Well, here’s your chance to spring a free copy! The marketing folks have given the go-ahead to hold a giveaway, and have set aside four copies for lucky winners. A longer description of the How-to is on their site.
All they want to know is what you, as a prospective reader, find most interesting or potentially useful about the book. My comment section will be open until May 8th for replies along these lines. If you are selected, Packt will email you with information on how to get your free digital copy. If your comment catches our attention, you’re one step closer. If you want a print copy, they’re available from Amazon separately.
- Free book
- What interests you about it?
- Submit a comment
- You’re entered
I look forward to forcing Packt to do some community service by handing out free copies of the book, and you should too.
March 15th, 2013 |
Rant, Tech Talk | No Comments
Mid March is an interesting time of year in 2013. Now that the Galaxy S4 has been announced, there are really three major contenders for my itchy spending finger. Well, technically there are four, but one of them doesn’t really count, for reasons I’ll expound upon shortly.
Google Nexus IV
This is the phone that doesn’t count. One major benefit it has over all of the others, is that it gets updates directly from Google. Any Android advances are adopted in very short order, without any of the usual US carrier shenanigans. Unfortunately Google seems to believe 16GB ought be enough for anybody. Not only is 16GB the largest amount of memory in this particular phone, but since it doesn’t have an SD-card slot, it’s the most anyone will ever have.
Google believes The Cloud can supplant the need for large amounts of storage. It is wrong. Not only are some games on Google Play over 2GB in size, but carrier reception is hardly ubiquitous, and bandwidth is anything but generous. Anyone depending entirely on The Cloud for their entertainment will quickly find themselves tune-less or over their (likely 2GB) bandwidth cap in short order.
In a few years this may no longer be an issue, but now, in 2013, it is very much relevant and a limiting factor. Phones need at least 32GB of storage, and the ability to add more is often appreciated.
There are many—possibly millions—of people that can ignore this shortcoming, and the sales of the Nexus 4 have been booming. I however, do not count among their number. The other relative strengths or weaknesses of this device are heavily outweighed by this one missing feature, so I won’t even mention them. This phone doesn’t count in my list, and it’s a shame.
Sony Xperia Z
Sony? What? When did Sony make a good smart phone? Apparently they’ve woken up and decided they want to actually compete in the arena, and delivered what many agree is a very strong entry. 1080p screen, quad-core Snapdragon, 13 megapixel camera, a big 2330 mAh battery, SD-card slot, NFC chip, it’s mostly all there. Amusingly, they also made it waterproof, which is a big plus for all those accidental drops into puddles and the occasional toilet.
What’s not so great is that they didn’t include wireless charging, a strange thing to omit in a waterproof device. Needlessly opening up the USB port cover for charging could eventually wear it out. And though they actually have an SD-card slot, the phone itself only includes 16GB; there are no 32GB or 64GB versions. Oddly, it’s also only compatible with SD-cards up to 32GB. Again, 64GB cards are old news these days, and a strange thing to leave out.
The phone is also hilariously expensive at $850 off contract, and for all that, most reviews ding the screen for its relatively bad viewing angles. Anyone who watches media on the 5-inch screen while it’s on a kickstand may find that unacceptable. The battery life is also reportedly on the low end.
Yet a few gripes are what anyone would expect. All in all, it’s a device I could live with. That’s more than I could say about the Nexus 4.
Go home HTC, you’re drunk. You’ve already had a One S, a One X, and possibly everything in between. Whoever is in charge of your marketing and branding division should be dragged out into the street and shot. Why?
Because this phone is fucking beautiful, that’s why. It is hands-down the best looking Android phone I have ever laid eyes upon. The 4.7 inch-screen isn’t quite as large as Sony’s 5-inches, but it’s still 1080p. The two-tone machined aluminum shell with black accents is breathtaking, but it’s also functional. The top speaker grill obscures the notification LED so it isn’t so obtrusive. The stereo speakers are prominently on the front of the phone, and reviewers have gushed at how amazing they sound.
The power button on top? Ok, that’s somewhat odd. But it also doubles as an IR-blaster. Finally, a phone I could use as a TV remote! Jesus, why has it taken this long to add this? A couple well-designed universal remote apps could render remote juggling a thing of the past. It also has 802.11ac, the newest (draft) standard in wireless. Not really essential until compatible routers are more ubiquitous, but it’s a nice touch. They also opted for a larger camera sensor instead of simply higher resolution. The pictures totally blow away those from other recent phones. That said, they probably went too low with 4MP. What looks great on a phone may not look so well when printed or zoomed for editing. Anything larger than a 3×5 print will look grainy. Not really a problem for me, but some might be unpleasantly surprised when at the copy shop.
Like the Sony Xperia it has no wireless charging. No induction coil will really work effectively through the aluminum shell. And while it comes in a 32GB flavor, unlike the Nexus 4, it has no expandable storage. What may be worse: it can’t be disassembled to replace the battery if it goes bad. That aluminum shell with polycarbonate injection molding is effectively a beautiful, inaccessible slab.
Why do I care? The battery in my Galaxy S2 went bad. Not only did it not hold a charge, but the phone acted very oddly regardless of the reported power level. Eventually I returned the bloated ruin and received a replacement. With an HTC One, they’re most likely going to offer a replacement phone, and take the old one for refurbishing because it has to go back to a factory for a new battery. That, or I throw it away and buy a new phone. That kind of disposable planned obsolescence makes me exceptionally angry, especially considering how much the One is likely to cost off contract. At least the Nexus 4 is only a few screws away from a new battery.
So the awesome is tempered with some very real annoyances. And worse, even those who could forgive the permanent battery may never even know about the phone at all. HTC’s marketing budget was actually cut by 15% this year, and like I said, most people would naturally assume the One is an older version of the One X or some other HTC variant. HTC failed big-time in this regard, unless they start a new trend like what we see in the automotive industry. I mean, a Hyundai Sonata can vary greatly between model years, but its name never changes.
If that’s the direction they’re going, I wish them all the luck in the world. This endless stream of sequential numbering and nonsensical buzzword-rich names is long since tiresome and idiotic.
Samsung Galaxy S4
And finally, the most recently revealed entry in the Galaxy series. I could say a lot about Samsung, but their phone division is some kind of magical beast straight out of ancient mythology. It has every feature from all the phones I just mentioned, and then adds a few just for good measure.
Five inch screen? Yep. 1080p? Of course. 13MP camera? Why not? NFC chip? Duh. 2600 mAh battery? Holy crap! Wireless charging? It would be stupid not to. Barometer? Sure. SD-card? Is 64GB enough for ya? Internal memory? Up to 64GB, because Fuck You, every other phone. 802.11ac? No contest. A dual quad-core Exynos 5? You better believe it. 2GB RAM? Why use less. IR-blaster? Suck it, HTC. Less than 8mm thick? Anything thicker is only suitable to pave sidewalks. Replaceable battery? Only if you think a trunk is an essential feature in your car (it is).
And it goes on and on like that. The only real problem with the S4, is that it’s as ugly as balls. Seriously. I can hardly believe this is the same company that made the S2, which was as functional as it was good-looking. The S3 was a hideous Lovecraftian writhing horror by comparison. It’s sad to see Samsung continue that trend by only slightly revising that revolting design, especially after witnessing the ethereal perfection that is the HTC One. But we can’t have everything we want, and I’d rather have features I’d use than a phone to attract the drool of filthy passers-by.
It’s too soon to say how well the battery performs, but it’s bigger than what they put in the original Galaxy Note, a much larger device. And since it was just announced yesterday, there aren’t a lot of long-term reviews out there, but it looks like this is the top of the heap for people who don’t mind that it resembles regurgitated anus. While I would prefer something as classy as the HTC One, the S4 stomps all over it in terms of features. Provided it isn’t a buggy mess and the dev community provides some good ROMs, it’s very likely this will be my next device when it’s finally available in the US.
This is why Samsung sells a ton of phones and has become the top grossing Android manufacturer. It’s not just the endless buckets of cash they spend on marketing, but the fact they somehow cram every iota of functionality into their devices. People aren’t blind to that. HTC can make snide comments about it all day long, but until they can give us all the features Samsung does, they can shut the hell up.
And I’m sorry Sony, you really tried this time. I’m honestly shocked at how well the new Xperia compares to the S4. The fact they made a waterproof phone and still managed to add an SD-card slot is commendable. See that HTC and LG? It’s not impossible. But the Galaxy is just… more. Somehow, it always is. How? I have no clue. It should be impossible to be so consistently ahead of everyone else.
Honestly, HTC should be glad Samsung apparently hires drunken orangutans to design its phones. Does HTC actually want a good looking Galaxy device to compete with? Fuck no. How would HTC compete then? Still, HTC almost had me with the One. If not for the battery being firmly embedded in about five acres of aluminum, I may have even bought it despite having fewer features. It’s that enticing. Seriously, just fucking look at it. Why, Samsung?!
Oh well, the consumers are the winners here no matter what. I for one, love the competition. Come April, my S2 is going to be on Craigslist, and I’ll have to re-train my thumb for another half inch of real-estate.
December 27th, 2012 |
Contemplation, News | No Comments
About a week ago, I was prescribed Lexapro. While this may not be the stuff I’m on long-term, it’s still long overdue for reasons obvious to anyone who knows me.
What I currently find most interesting about it however, is actually related to a dream I had last night. My dreams tend to be very vivid and numerous, though sometimes they follow a theme or storyline. Last night, there was one particular scene I recall with such clarity, it’s almost difficult to accept I wasn’t awake. Clearly I was asleep, and obviously it didn’t happen, but the fact it’s burned into my long-term memory is very strange.
In this portion of the dream, I was about to take some of my Lexapro. For the first few days, the doctor wanted me to take half doses, and my sleeping brain still had a firm grasp of this constraint. But alas! Upon pouring the pills into my hand, I accidentally dropped them all on the floor. Did I mention I was at work? And for some reason, work in my dream had shag carpeting? While bent over and putting all the pills back into the bottle, I was worried I wouldn’t get them all. So worried in fact, I was basically just shoving various floor detritus into the bottle. I even picked carpet fibers from one of the split tablets; I didn’t want to lose any!
This included some rotten vegetables (why?) that were also tangled up in the carpet. Realizing my mistake, I carefully extracted the vegetables from the bottle, but then noticed the pills were gone! What happened to them? They were dissolved by the juices of the rotten produce, which was now all over my hands. Somehow the tablets I had cut in half—the whole reason I had to pour them into my hand—had become capsules and also dissolved into the goo. The new worry of course, was that I had overdosed by osmosis.
Work was having a big party that night, but of course I had to leave because I needed to get my prescription replaced. Leaving the party was partially a relief, because of course I hate large gatherings of people. And wouldn’t you know it? I forgot the bottle, so I had to go back into work and retrieve it before I could actually leave.
Now, the dream itself had a few other elements I somewhat recall, but details are sketchy and I’d be too tempted to fill in missing pieces. The part about dropping everything, picking through the carpet, and then having Lexapro-infused veggie goo all over my hands was extremely vivid. I didn’t sleep well last night in general, waking up a couple times and then just being awake for no reason, so it’s good to know I got some sleep. But the fact my dreams centered on a bunch of worrisome BS is hardly relaxing.
I now realize I do that quite often. Some of my dreams are grand adventures, but another portion of them are just a bunch of worrying about things. It’s ridiculous, really. My only real hope is that the Lexapro isn’t contributing to my periodic insomnia. That’s really the last thing I need right now.
May 19th, 2012 |
Rant | No Comments
Seriously, just stop. All of you are acting like children. Not merely children, but spoiled little selfish brats, and it’s embarrassing to everyone. You should be ashamed of yourselves.
I’ll tell you, and it’s not what you might expect to hear. It isn’t about fanboys or fangirls, theft of intellectual property, laughably vague patents on generic concepts which could feasibly apply to practically anything, jealousy, innovation, or even the almighty dollar. It’s all of these things, yet none of them, for which you should avert your attention to the ground and sheepishly beg our forgiveness.
The first person you should address is Sir Isaac Newton, one of the greatest mathematicians and scientists who helped define our modern world. He once wrote in a letter of his achievements, “If I have seen further it is by standing on ye sholders of Giants.” Without his work, there would be no software to copy.
Then you can turn your attention to Nikola Tesla, whose inventions make mobile communication and electronics possible. Tell him how you’ve patented not clever engineering you’ve created, but shapes and styles, colors and words. Say to his face, how your patents on end results are just as legitimate as his for demonstrated methodology. If he acted as you have, there would be no computers at all.
I could go on, but then this rant would be effectively endless. In your world, there would be no cars, just “Conveyance devices constructed of metal, equipped with an engine capable of turning one or more wheels to provide propulsion in any direction.” That would cover everything from motorcycles to trains, and they’d all owe royalties to whomever had their name on that particular patent.
But why do you even have that patent? It’s because Mr. Tesla made radio possible. It’s because Newton figured out the physics and math to describe and define it in such a way it was repeatable and logically sound. You would have nothing, all of you, without the hundreds and thousands of inventors and designers throughout history who made your existence possible. Yet in your greed, instead of thanking these men and women for their contributions, you claim for yourselves the fruits of their labor. As if it was only through your effort that your ridiculous assertions have merit.
You have no sense of perspective. You’re poisoning the very industry you claim to represent, and it’s reprehensible. The vicious momentum that wrenched us from the industrial revolution to the age of the internet is literally being violated by your frivolous attempts to keep the profits of these advancements for yourselves. You have transformed yourselves from leaders and innovators into pustules upon the technology sector, wretched and cantankerous old men, jealously hoarding the spoils of your endeavors and attacking anyone who dares look upon you.
When time has moved on and your influence finally wanes, you will not be remembered as giants who propelled us forward, but contemptible fonts of greed and avarice that stifled technological progress for decades. Your name will be a curse upon the lips of mankind, and your leaders as whispered threats meant to scare children to behave. You are pathetic and everyone can see it as you righteously assert yourselves over competitors large and small, with no regard for those of us caught in the crossfire who must endure your ignorance.
That is the future and perception you have chosen for yourself. I hope you enjoy your current success, because it shall turn to ashes in your mouth, and evoke only hate from everyone you’ve alienated along the way.
« Older Posts
Newer Posts »